It’s in the docs. https://gohugo.io/templates/introduction/#1-define-a-variable-independent-of-context
I strongly recommend reading all of the docs, and then trying to actually create a Hugo project. Then when you have a specific question, you can share your code and point to what part of your code is confusing or does not work.
Also useful to read Requesting Help and Recommended Reading Reference