node.js - Are variables defined in the global context accessible when there's name collision? -


If I want to define a variable, define the global context from within an area where already equal A variable with the name exists:

  var variable = 'value'; Function someScope (variable) {variable = 'this not'; Var global = function ('return it') (); Console.log ('this & gt;', global.variable); }   

Can still reach any kind of global expanse?

Neither the global object nor the works. ( global.variable returns are undefined)

if the variable is actually global It's global Can access through the name, even if there is a collision with a local variable. For example

  // notice is not "var" here variable = 'global'; Function someScope () {var variable = 'local'; Console.log (variable); // local console.log (global.exchangeable); // global} someScope ();   

However, if you define your variable with "var" at the top of the file (as you are in your code) then it will not be global and you will get different results Meetings (i.e. Global.Variable Print Undefined.)

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -