loading...

re: Confused by JavaScript's const? Me too! VIEW POST

FULL DISCUSSION
 

I think objects are referential (like a pointer in other languages) so the const is the reference to that object. At least that is what I tell myself so I can sleep at night 🤣

 

Yes, objects are passed by reference, but there are no pointers in JavaScript. We can't have direct access to memory addresses like in C language.
I wrote a mini-post describing how references in JS work with objects. By walking through a simple example, it shows that a variable can't reference another variable.

 

It is not important if language provides access to memory or not. Pointer is always address to some space occupied by data regardless of programming language.
If you will have one object and this object you will put into 500 arrays, you still have only one object on the same address (on the same pointer).
So we can say that even javascript has pointers/addresses.

I agree that under the hood there are pointers, memory allocation, e.t.c. I mean that JavaScript doesn't have syntax to work pointers directly and allocate/free memory like it's done in C or similar languages.

code of conduct - report abuse