Good article in general; but the point on Global block binding is misleading. var is sometimes tied to the current scope; so is not always added to the window object:
var
var foo = "foo"; // global if(true) { var poo = "poo"; // leaks from scope let moo = "moo"; // scoped } function myFunction() { var bar = "bar"; // scoped }; console.log(window.foo); // foo console.log(window.poo); // poo console.log(window.moo); // undefined console.log(window.bar); // undefined
The reason it has been superseded by let (and const where appropriate) is because it leaks from some scopes and this was a common source of bugs.
let
const
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good article in general; but the point on Global block binding is misleading.
var
is sometimes tied to the current scope; so is not always added to the window object:The reason it has been superseded by
let
(andconst
where appropriate) is because it leaks from some scopes and this was a common source of bugs.