Let and const are new keywords in ES6. They differ from var in the following ways:

1. Scope

There are only two types of scope in ES5, a global scope and a functional scope

Var declares a variable that can be accessed anywhere in the containing function, module, or global scope, either globally or as an entire enclosing function

Let /const declared variables/constants have block-level scope and can only be used within the declared code block

2. Duplicate declaration/assignment

Var can be declared repeatedly and can be declared without initial assignment

Let is not allowed to be declared repeatedly in the same code block, but the same variable can be declared in different code blocks, and let can be declared without initial assignment

Const is a read-only constant. It cannot be declared repeatedly, must be initialized, and cannot be changed. A const is immutable, meaning that the memory address to which it refers cannot be changed, and its internal value can be changed if a reference type (such as an object) is declared

3. Variable boost/temporary dead zone

Var has variable promotion, that is, the variable can be accessed before the variable declaration, the value is undefined

Let and const have no promotion. The amount they declare is not available before the declaration. This is called a temporary dead zone for let and const