let and const keyword
- JavaScript let is a keyword used to declare variables in JavaScript that are block scoped.
- JavaScript const for declaring variables with immutable values, enhancing code stability and readability.
Syntax:
let variable_name = value; // let keyword
const const_name; // const leyword
const x;
Example: Here is the basic example of using let and const keyword.
Javascript
// Using let let x = 10; // Allowed, since x is declared with let x = 20; console.log(x); // Outputs: 20 // Using const const y = 5; y = 8; // Error! Cannot reassign a const variable console.log(y); |
Output:
20
TypeError: Assignment to constant variable.
JS 2015 or ECMAScript 6 (ES6)
JS 2015 (ES6) also known as ECMAScript 6 (ES6), ECMAScript 6 (ES6) is a significant update to JavaScript, introducing arrow functions, classes, template literals, let and const for variable declaration, enhanced object literals, destructuring, and more modern features for better code organization and readability.
Contact Us