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,330 0 JAVASCRIPT SCOPE NAME RESOLUTION
var in JavaScript
Geoff published an article sometime ago--"How one missing var ruined our launch". This article described one case where MelonCard uses Node.js as their backend system, suddenly there was a small registration peak period--50-100 people registered concurrently, then the entire website stopped responding and many other strange problems showed up. When they were investigating the source of the problem, they found one missing var in the following code.app.all(‘/apps/:user_id/status’, function(req, res, next) { // … initial = extractVa...
3,609 0 JAVASCRIPT VARIABLE SCOPE