DEV Community


Discussion on: Some JavaScript Principles you should know.

blindfish3 profile image
Ben Calder

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 foo = "foo"; // global
if(true) {
  var poo = "poo"; // leaks from scope
  let moo = "moo"; // scoped

function myFunction() {
    var bar = "bar"; // scoped
console.log(; // foo
console.log(window.poo); // poo
console.log(window.moo); // undefined
console.log(; // undefined
Enter fullscreen mode Exit fullscreen mode

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.