Thursday, May 24, 2018

Difference between let and VAR in JS
The let statement declares a block scope local variable, optionally initializing it to a value.
Description: let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.
An explanation of why the name "let" was chosen can be found here.
Scoping rules:
Variables declared by let have their scope in the block for which they are defined, as well as in any contained sub-blocks.
The main difference is that the scope of a var variable is the entire enclosing function.
see full details about let with examples.

No comments:

Post a Comment