You are viewing a single comment's thread from:

RE: JavaScript - var, let, const

in #programming7 years ago (edited)

OMG!
I didn't know that this would work:

function a() {
  var a = 5;
  if (true) {
    var a = 10;
  }
  console.log(a); // prints 10
}

Does it work same in NodeJS as well?
Usually I don't reuse variables in the same function, but it could mess up my code if I'm not careful!

Extremely valuable, thanks for sharing!

Sort:  

Right!, Thanks for the another cool example!