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,041 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,335 0       JAVASCRIPT VARIABLE SCOPE


  How One Missing `var` Ruined our Launch

Well, that was a veritable shitstorm (sorry for the language).  Long story short, MelonCard was featured today on TechCrunch (along with other500Startups companies, also on VentureBeat, Forbes, …) and everything broke all at once.  Every. little. thing.  We had rolled out a huge change to MelonCard over the last few days to make our site a seamless “everything just updates” look-good / feel-good product using NodeJS long-polling with a slick KnockoutJS dynamic jQuery Templates front end.  We did our du...

7,443 2       JAVASCRIPT JQUERY NODEJS VARIABLE SCOPE GLOBAL