Const keyword in JavaScript

Maged
Jul 4, 2021

const is a keyword used to declare variables in JavaScript

const :

const is used to create a read-only reference variable because the value referenced by const cannot be reassigned. Means it is usually used to declare variables that you don’t want their values to change later.

cannot assign “a” another value

once a variable is declared using const, it has to be initialized.

const has to be initialized when declared

const is a block-scoped means that a variable declared using const keyword is available only in the block it was declared in. it is similar to the scope of let keyword.

const is block-scoped

we can use const to create an object which will have all same rules as a variable (cannot be reassigned, has to be initialized, block-scoped), but the properties’ values can be changed.

const keyword to declare an object

--

--