Course Banner


Const keyword

Let's check few of the above mentioned points below:

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

Now if we try to declare the constant again with the same name then it will throw an error.

const x = 100;Const keyword

If you know the basics of Javascript, you might be knowing about variables. The value of the variable is overwritten during program execution.
On the contrary of this if you want to keep the value the same, and do not want to overwrite then the keyword const is used for that.

<!DOCTYPE html>

<html>

<body>

<h2>The value of const is : </h2>

<div id="result"></div>

<script>

//const x = 2;

const x = 100;

Const x =200;

You will see this error 

const.html:14 Uncaught SyntaxError: Identifier 'x' has already been declared