Arrays with let and const


“we can change the contents of a const array, but cannot reassign a new array or a different value.

const utensils = [‘Fork’, ‘Knife’, ‘Chopsticks’, ‘Spork’];
utensils[3] = ‘Spoon’;
here can i say the value of utensils has been reassigned?
is the contents of a const array the same thing as a value ?

Thanks for your help!


In global scope the only declaration that has any meaning is const. The rest (var, let) are fluff Learn the meaning, not the presents.

Variables declared with the const keyword

is an oxymoron. They’re not vairables if they’re constants. In this instance the term name would have meaning.


Sorry! I am still confused about what you replied. :sob:
Why only does const have any meaning?


In global scope it is the only one that is not moot. var and let are block scope declarations, and since window is the top of the scope chain any variable declared there is global. Likewise any variable defined in block scope without the declaration (const, var or let) will also be global.

In global scope,

a = 42

is the same as,

var a = 42

Note how the variable defined in a function without var is accessible outside of the function…

function foo() {
    a = 6;
    var b = 7;
console.log(a)    // 6
console.log(b)    // Uncaught ReferenceError: b is not defined