Mmastodon TechnologySoftware first seen 16 h ago, last 16 h ago, peak #12
JavaScript's const surprises developers with mutable objects
Original: You use const because you don't want a variable to change. But JavaScript has a surprise for you. 👀 const user = { name:
A popular code example is reminding developers that JavaScript's const keyword does not make objects immutable. Declaring an object with const prevents reassigning the variable itself, but its properties can still be changed, as shown by modifying a name property without error. Developers are revisiting the distinction between const declarations and true immutability, and discussing workarounds like Object.freeze.
Why now: A widely shared code example highlights a common JavaScript misconception about const and object mutability.
Evidence
- You use const because you don't want a variable to change. But JavaScript has a surprise for you. 👀 const user = { name: "Rahul" }; user.name = "Alex"; console.log(user.name); Output: Alex Wait… wasn't user declared with const? Here's the trick. const prevents you from… · devto@www.urbanmind.net · 2
API: https://socialmediatrends-api.osmike.com/v1/trends/1891383