As talked about in our JavaScript Hiring Guide, a typical wellspring of disarray among JavaScript designers (and along these lines a typical wellspring of bugs) is accepting that JavaScript makes another extension for each code piece. Despite the fact that this is valid in numerous different dialects, it isn't valid in JavaScript. Consider, for instance, the accompanying code:
for (var i = 0; i < 10; i++) {
/* ... */
}
console.log(i); // what will this output?
In the event that you figure that the console.log() call would either yield vague or toss a blunder, you speculated erroneously. Trust it or not, it will yield 10. Why?
In most different dialects, the code above would prompt a blunder on the grounds that the "life" (i.e., scope) of the variable I would be confined to the for piece. In JavaScript, however, this isn't the situation and the variable I stays in scope even after the for circle has finished, holding its last an incentive in the wake of leaving the circle. (This conduct is referred to, by chance, as factor raising).
It is important, however, that help for square level degrees is advancing into JavaScript through the new let catchphrase. The let catchphrase is as of now accessible in JavaScript 1.7 and is slated to end up noticeably an authoritatively bolstered JavaScript watchword as of ECMAScript 6.
New to JavaScript? Read up on extensions, models, and the sky is the limit from there.
0 comments:
Post a Comment