Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS Let

Introduced in ES6 (2015), the “let” keyword in JavaScript is utilized to declare variables with block scope. Variables declared with “let” must be declared before they are used, and they cannot be redeclared within the same scope.

Block Scope

Prior to ES6 (2015), JavaScript primarily featured Global Scope and Function Scope.

With the introduction of ES6, two new keywords, let and const, were added.

These keywords introduced Block Scope to JavaScript.

Example

Variables declared within a { } block are inaccessible from outside that block.


  var x = 2
}
// x CAN be used here