Home Global variable at top of the JavaScript file
Reply: 0

Global variable at top of the JavaScript file

user655
1#
user655 Published in July 18, 2018, 10:21 pm

Say I declare a global JavaScript variable at the top of a JavaScript file to equal 0

i.e.

var jVar=0; 

Then I call a function in the JavaScript to set that variable to 1 ie.

function setVarToOne(){
    jVar=1;
}

If I then reload the page what will the variable equal before the setVarToOne function is called ?

Will the jVar keep the value it was set to in the function or will it be re-initialised to 0?

What I need to understand is, what happens to JavaScript variables when the page is reloaded?

Thanks

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310134 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO