1

is there any way to get the memory address of the JavaScript variable , cause when comparing things like [1,2,3] === [1,2,3] which is looks like true but it is false , and also this memory address will help me to understand mutable and immutability of strings too

7
  • 1
    no, and you never need to .. .looks like true only to the uninitiated :p Commented Jul 6, 2022 at 5:16
  • Removed all those tags that are irrelevant. (Im)mutability is not explained by memory addresses. Strings are always immutable in JavaScript. Commented Jul 6, 2022 at 5:21
  • comparing arrays where all the values are primitives (with the exception of Symbol) can be done... [1, false, 4n, "hello"].toString() === [1, false, 4n, "hello"].toString() Commented Jul 6, 2022 at 5:25
  • 1
    @trincot - aren't all the other primitives immutable too? (Number, Boolean, BigInt, Symbol) Commented Jul 6, 2022 at 5:25
  • 1
    @lucky, but object variables that have the same address can reference a mutable object or not, and object variables that have a different address can reference a mutable object or not. It doesn't relate. It doesn't help to know an object's address to say anything about immutability. Commented Jul 6, 2022 at 5:31

1 Answer 1

1

JavaScript itself is meant to be implementation-agnostic, so concepts like memory addresses are intentionally absent from the language itself. Outside of the language, you can use the browser's debugging tools to take a memory snapshot, and that might contain the information. Note, however, that there is no real guarantee that an object will retain its address.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.