30 Day JavaScript Learning Challenge: Day 10

Today's learning challenge focused on Javascript's functions and scoping rules. Like most things JavaScript the rules are a bit off from my expectations. Take this for instance:

var something = 1;
{
    var something = 2;
}
console.log(something);

What is the value of something? If you said '1', JavaScript reminds you that it's not like other languages where braces denote scope. Nope, instead variables are defined at the function level, and the scope of the function hasn't changed just because there's braces.

Apparently there's going to be a new let keyword that will do what you would expect. But for now it's one more thing to keep in mind in the bizarro world of Javascript.

And once again I wonder what folks see in this language.


links

social