ES6
School

Learn the fundamentals of ES6 features with examples for just $5. No bullshit ever. See an example below.

Example


"Let" keyword


Let is very similar to var but it is only accessible in the block level it is created.


let keyword example


In the above example variable ‘a’ is defined inside If statement and so it’s not accessible outside the function.


Let's see another example



let keyword example


let vs var


The difference between let and var is scope. var is scoped to the function level whereas, let is scoped to the nearest enclosing block.


Let's see another example


let keyword example


The above example is very self-explanatory. var is accessible even after the For loop whereas, let is only accessible inside For loop.


So it's a very good practice to use let whenever possible to avoid scope problems.

© ES6 School