Declaration of a variable (let and const) in javascript ES6

share link

by vsasikalabe dot icon Updated: Mar 16, 2023

technology logo
technology logo

Guide Kit Guide Kit  

In JavaScript, users can declare a variable using three keywords (var, let, and const). The let variable is declared using the let keyword accessed within the block scope. Block scope is nothing but a section or function{}, a block{}, or a global (script) where the let variable gets declared. The const variables in ES6 have a new way to declare a constant using the const keyword.  


The keyword const is created and has a read-only reference to the value. The const variable has some properties that are as follows: 

Properties: 

  • We cannot reassign a value. 
  • It has a block scoped. 
  • A constant cannot be re-declared. 
  • It must be initialized at the time of declaration. 

Global Scope: We can access the variable from any part or section of the JavaScript code in Global scope. 

Local Scope: We can access the variable within a function in the local scope where it is declared. 

They are all hoisted to the top of their function or scope. Const must be initialized during declaration. Without being initialized, var and let can be declared. 

Note these points before declaring a variable

  • Don't use var anymore. 
  • Use let or const. 
  • Use const more often.  
  • You can use the let keyword when you need to reassign another value to a variable. 
  • Only try to access a variable after declaring it. 


Here is an example of how to declare Variables (let and const) using Javascript ES6: