Course Banner

Let Keyword

The let keyword allows you to declare a variable with block scope.

The main difference between let and variable is that variable works on the whole page while let works on block level.>

Lets understand this with the below example:

<!DOCTYPE html>



<h2>Using let keyword in Javascript</h2>

X value from Let Keyword : 

<p id="result_let"></p>


X value from var Keyword : 

<p id="result"></p>


var  x = 10;

// Here x is 10


  let x = 2;

  // Here x is 2

  document.getElementById("result_let").innerHTML = x;


// Here x is 10

document.getElementById("result").innerHTML = x;