DEV Community

Discussion on: Const Is A Lie In JavaScript & Mastering Unit Testing

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

But here's the thing about const in JavaScript: it ONLY makes sure that the reference isn't reassigned. But when you use a keyword like const, it implies to you that the thing you're creating is constant, and will remain unchanged throughout the life of the reference. But that's not true.

It is true. The reference (pointer) cannot be reassigned. The object that is being referenced/pointed to can still be modified. In C++, this is the equivalent of a constant pointer to a non-constant object.