Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
SD01042028ySorry one more JS rant, can't help it
(earlier saw a rant about 'Javascript infested water') :/ -
that is perfectly correct since "const" only prevents for REASSIGN the variable. The foo var in your screenshot is an array that has been ADDED a key-value pair, but the array hasn't been reassigned :)
-
SD01042028y@javierojeda
You means to say object
Yes you are right its not reassigned but i just mentioned the words of that tweet -
oh yeah, it's an object sorry :p but I've seen a very large number of people saying that "const" is a stupid thing, however it is just a misconception of what the variable type actually does... some developers need to read more u.u
-
kheftel6528yConst does not mean the contents of an object can't change, it just means you can't change the pointer to point to another object.
Haven't done C++ in awhile but I think a similar concept would apply if you exposed a const property that is an object, you can't reassign to another object but you can call calls on that object that change its state. -
SD01042028y@kheftel
Yes
But to make it immutable we can use freeze method, it will not even allow to change the value of an Object during run time
Const is officially just introduced in ES6 so many people are not aware about it but freeze is an ES5 - ES5.1 method -
maman98yIt just prevent you to change the reference of that variable. Most people think that const is "immutable", where it clearly isn't
Related Rants
So a 'const' value can definitely change :|
JavaScript ES6 :|
undefined
js
es6
javascript