DEV Community

Discussion on: Share a code snippet in any programming language and describe what's going on

Collapse
 
moopet profile image
Ben Sinclair

Const doesn't denote read-only, it only means you can't reassign it in the same scope. You can mutate it all you want (provided it's a type that's mutable in the first place)

const x = [1, 2, 3];

x.push(4);
delete x[0];

// [ <empty slot>, 2, 3, 4 ]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
crowdozer profile image
crowdozer • Edited

I worded it a bit slopy, a "read-only reference to a value" according to MDN, but it's all semantics as long as we understand how it works =]