Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Name resolution order in JavaScript

To understand what value a variable has in JavaScript, we need to understand some concepts such as scope and name resolution order.JavaScript has two scopes; one is program level and the other one is function level. Unlike in C,C++ or Java, JavaScript has no block level scope. So a variable defined in a if block will still be available outside. For example, the below example:var foo = 1;function bar() { if (true) { var foo = 10; } alert(foo);}bar();The alert will display 10 since the variable foo defined in the if block can been seen by the alert() function.Next we need to understand the name...

7,074 0       JAVASCRIPT SCOPE NAME RESOLUTION