When you are coding a theme you usually edit standard files such as index.php, single.php, page.php and so on.
In these files you might have noticed that some variables are available even though you have not declared them. Such a variable would be $post for example.
But which other variables are available?
To find out, take a peek in the function load_template in wp-includes/theme.php. In this function alot of different global variables are declared. Normally, theme files are loaded through template-loader.php and to find out exactly which variables are available in that variable scope might be tricky, but the global variables in this function gives us an idea.
Also, all the variables in the query_vars array are extracted and made available.
A way to make a custom variable available in your files would be to simply declare it in your theme’s functions.php file.