Const can be updated if it's an object or array. This is fine, for example:
constfoo=[];foo.push("hello");
So const is kinda-sorta-const, depending where you learned the word "constant". You can't redeclare it or make it point at anything else, but you can modify it if it's a container for other things.
Hello, World! I'm jzombie, a passionate software developer with a knack for problem-solving and a love for open-source. I believe in the power of code to change the world and make our lives easier.
Const gives you a constant memory reference. You can't reassign the memory reference, but any properties can be [re]assigned. The constant value assumption is only for primitive types.
I am a Software Engineer proficient in Web development and have experience in various technologies. Inspired to automate the boring stuff, solve challenges, and innovate new digital solutions.
I'm a coder who has worn a lot of hats, from individual contributor to lead engineer to "CTO" (yes, in quotes, make of that what you will!). I've plenty to learn and hopefully some to share as well.
It's not a reference to specific memory. The thing pointed to by a const variable can and often will move locations in memory (for example if you keep pushing onto an array, the engine will eventually have to allocate a new, bigger block of memory for it). It's just a constant reference to a specific value.
Hello, World! I'm jzombie, a passionate software developer with a knack for problem-solving and a love for open-source. I believe in the power of code to change the world and make our lives easier.
I am a Software Engineer proficient in Web development and have experience in various technologies. Inspired to automate the boring stuff, solve challenges, and innovate new digital solutions.
The computer science definition of constant existed for forty years or more before JavaScript decided to use the same term for something different than most computer languages and in mathematics.
We're a place where coders share, stay up-to-date and grow their careers.
Const can be updated if it's an object or array. This is fine, for example:
So
constis kinda-sorta-const, depending where you learned the word "constant". You can't redeclare it or make it point at anything else, but you can modify it if it's a container for other things.Const gives you a constant memory reference. You can't reassign the memory reference, but any properties can be [re]assigned. The constant value assumption is only for primitive types.
To freeze objects: developer.mozilla.org/en-US/docs/W...
I'll check on this. Thanks for the feedback
It's not a reference to specific memory. The thing pointed to by a const variable can and often will move locations in memory (for example if you keep pushing onto an array, the engine will eventually have to allocate a new, bigger block of memory for it). It's just a constant reference to a specific
value.Thanks for the clarification.
Thanks for this information, I will learn it and update it
The computer science definition of constant existed for forty years or more before JavaScript decided to use the same term for something different than most computer languages and in mathematics.