Function Scoped JavaScript Variables ACCESS on a 'NON Strict Mode '

function scoped() {
  var a = 150;
  let b = 300;
  const c = 500;
}

a = 300; // Why is it possible to access a function scoped variable?
b = 600; // Same as above
c = 1000; // Same as above and also why I can change value of constant?

console.log(a); // Return: 300 - Why it works?
console.log(b); // Return: 600 - Why it works?
console.log(c); // Return: 1000 - Why it works?

MY QUESTIONS:

  1. Why it is possible (in a non strict mode) to access function scoped variables? Should this NOT be allowed?

  2. Why I can even change a value of a constant?

  3. How does scope or hoisting work behind the scene in this specific case?

23 thoughts on “Function Scoped JavaScript Variables ACCESS on a 'NON Strict Mode '”

Leave a Comment