DEV Community

Discussion on: Why you shouldn't reassign values in JavaScript

Collapse
 
shalvah profile image
Shalvah • Edited

They're not really "constants" in a strict sense because, even though you can't reassign, you can modify the referenced value (if it's an object). For instance:

const x = {a: 1};

// this will fail
x = {a: 2};

// but this will pass
x.a = 2;