ID: I202601271155 Status: idea Tags: JavaScript

javascript let vs var

In javascript you can define variables as a let, var and const.

let x = 10;
var y = 10;
const z = 10;

All the above variables will behave differently.

Var Var is accessible in the entire function scope. No matter where it is defined.

Let Let is only accessible in the codeblock where it has been defined. So if you define a let inside of a for loop, it won’t be accessible outside of the for loop.

Const Const is only assignable once, you cannot change the value of it. (Not counting object pointer changes, then we get into the stack and heap scenario.)


References

I was preparing for the Avans 2.1 Remindo Test