DEV Community

Anandhi P
Anandhi P

Posted on

Let and Const

Let:

let is a JavaScript keyword used to create a variable.

The value of a let variable can be changed later.

The let keyword was introduced in ES6 (2015)

Variables declared with let have Block Scope

Variables declared with let must be Declared before use

Variables declared with let cannot be Redeclared in the same scope

<!DOCTYPE html>

Javascript

var x = 120;
// Here x is 10

{

var x = 15;
//Here x is 2
}

// Here x is 2
document.getElementById("demo").innerHTML = x;

Const:

The const keyword was introduced in ES6 (2015)

Variables defined with const cannot be Redeclared

Variables defined with const cannot be Reassigned

Variables defined with const have Block Scope

const age = 20;
console.log(age); 20

const age = 20;
age = 25; // Error

Top comments (1)

Collapse
 
arokiya_kithiyon_1f2bad36 profile image
Arokiya Kithiyon

What is document.getElementById() ?