javascript - Get Global Variable Value After Applying Function in Another Script -


i have variable initialized no value in first javascript file, let's call first.js, this: var loggedinstatus;

then, in main function of javascript file, variable assigned value this: loggedinstatus = true

lastly, in javascript file, let's call 1 second.js, need access loggedinstatus variable value true assigned it.

i understand concept of loading first.js before second.js in html files using script tags, i'm wondering there way of passing on associated true value loggedinstatus variable?

if can define loggedinstatus inside global variable, can access it.

for example,

var loggedinstatus = 'j'; // global scope    (function(){ // non-global scope        loggedinstatus = true; // modifies global scope variable;    })();    alert(loggedinstatus); // global scope

you can use this, use apps.

window.app = {}; 

app global object can hold related app environment. can defined modify, delete variables, objects, or functions.

window.app = {};    console.log(app.loggedinstatus); // undefined    app.loggedinstatus = false; // set variable;    console.log(app.loggedinstatus); // false;    app.loggedinstatus = true; // update;    console.log(app.loggedinstatus); // true;    delete app.loggedinstatus; // delete;    console.log(app.loggedinstatus); // undefined


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -