Modify Array With Indexes

sir if a data is declared as a constant that means it will cannot be changed.but in Javascript course “Modify Array Data With Indexes”
Array is declared as a constant but still it is changes/modifying indexes…

Your code so far


// Setup
const myArray = [18, 64, 99];

// Only change code below this line
myArray[0]=[45];

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14388.61.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.107 Safari/537.36

Challenge: Modify Array Data With Indexes

Link to the challenge:

It is an important thing to understand: you can’t change what the variable points to

const arr = [1]
arr = [2] //error

But you can change the array

const arr2=[1]
arr2[1] = 2;
arr2.push(3)

console.log(arr2) // [1, 2, 3]
1 Like

we can change elements of const declared array, but can not change a whole array that is declared as const.

is that???

1 Like

Google reference vs value immutable.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.