JavaScript Array Const

JavaScript const keyword was introduced in 2015.  JavaScript array const is used very commonly. The arrays that are declared with const keyword cannot be reassigned:

The  const  keyword mislead a little bit because it is not used to define a constant array. It is used to define an array constant reference. Because of this feature, the elements of a constant array can be changed.

<!DOCTYPE html>
<html>
<body>

<script>
const language = ["Python", "C++", "Python", "Java"];
language[0] = "C#";
language.push("Html"); 
document.write(language);
</script>

</body>
</html>

Output:

JavaScript Array Const

Declaration

When the JavaScript const variables are declared they must be assigned a value.

JavaScript Array Const Block Scope

An array Block Scope declared with const has is same as an array declared outside the block:

Redeclaring or reassigning a const array, in the same scope or block, is not allowed:

 Supported Browsers for JavaScript Array Const :

  • chrome 21 and above
  • Edge 12 and above
  • Firefox 36 and above
  • Internet Explorer 11 and above
  • Opera 9 and above
  • Safari 5.1 and above

Common Questions about JavaScript Constant Arrays

What does JavaScript Array Const mean?

Assortments are not constants Const is a little bit deceptive as a keyword. There is no constant array defined. It establishes a fixed pointer to an array. As a result, a constant array’s components are still changeable.

In JavaScript, is it possible to declare an array with const?

JavaScript requires that we write const before the array name in order to create a const array. The entire array cannot be transferred, only its individual elements. 16-Jul-2020

What does JavaScript Array Const mean?

Assortments are not constants Const is a little bit deceptive as a keyword. There is no constant array defined. It establishes a fixed pointer to an array. As a result, a constant array’s components are still changeable.

In JavaScript, how do you write a constant?

The const keyword introduced in ES6 offers a new method for defining constants. A read-only reference to a value is created by the const keyword. The constant names are always capitalized as a matter of convention. The const keyword declares blocked-scope variables, just like the let keyword does.

What distinguishes a JavaScript Array Const from a normal constant?

While let and const are block scoped, var declarations are either globally scoped or function scoped. Let variables can be updated but not re-declared, const variables cannot be updated or re-declared, and var variables can both be updated and re-declared inside their scope. Each of them is raised to the very peak of their scope. 02-Apr-2020