JavaScript Const

JavascriptWeb DevelopmentObject Oriented Programming

The JavaScript const declarations create variables that cannot be reassigned to some other value or redeclared later. It was introduced in ES2015.

Following is the code for JavaScript const declaration −


 Live Demo

<!DOCTYPE html>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
<h1>Const example</h1>
<button class="Btn">CLICK HERE</button>
<p class="sample"></p>
<h3>Click the above button to try changing const value</h3>
   let sampleEle = document.querySelector(".sample");
   const a = 33;
   sampleEle.innerHTML = "a = " + a + "<br>";
   document.querySelector(".Btn").addEventListener("click", () => {
      try {
         a = 44;
      } catch (err) {
         sampleEle.innerHTML += "Error : " + err;


On clicking the ‘CLICK HERE’ button to change constant value −

Updated on 07-May-2020 14:04:50