4 comments

[ 3.2 ms ] story [ 19.1 ms ] thread
FUD.

w3schools doesn't, at all, make the claims this author is stretching for. In fact, on their JS Functions page (http://w3schools.com/js/js_functions.asp), w3schools state precisely what the author illustrates:

The Lifetime of JavaScript Variables

If you declare a variable, using "var", within a function, the variable can only be accessed within that function. When you exit the function, the variable is destroyed. These variables are called local variables. You can have local variables with the same name in different functions, because each is recognized only by the function in which it is declared.

If you declare a variable outside a function, all the functions on your page can access it. The lifetime of these variables starts when they are declared, and ends when the page is closed.

FACT.

There is a screenshot in the post, on your link it may be right, but on the link referenced in the post, it's wrong.

Actually, the statements in the image you posted are all outside of functions, and thus in the global context, so the statement that they are equivalent is true.
The problem is that particular w3schools page does not indicate that, they simply state that they are the same, without even slightly mentioning that it's because they are not in a function. My article shows off this difference. In short the page is misleading, because it doesn't state that the two are only interchangeable in those two examples, but not in in every situation.