javascript noob Q - set global variables for current page

Pat VachonPat Vachon ✭✭
edited June 25 in Questions
Is this post correct? 

Can I set a global variable inline that is not within any function and use this variable anytime I choose so long as I don't refresh the page?

For example, can I run a snippet which sets the value, so something in a popup, then run another snipper that used this global value.


  • edited June 25

    With JavaScript, the global scope is the complete JavaScript environment.  In HTML, the global scope is the window object: All global variables belong to the window object.  So you could do something like this

    var isDude = 'Pat';


    if (!window.isDude) { window.isDude = 'Pat; }

    Best practice is to not use global variables.

    I am not a JavaScript developer so nothing said or written comes with an expressed warranty.

    google-bing for lots of details and opinions.

  • Pat VachonPat Vachon ✭✭
    edited January 2016
    I wouldn't use a global variables in snippets could take in parameters when being called from an action.
Sign In or Register to comment.