How does JavaScript knows the variable identifier points to the specified memory address?

28 views Asked by At

Iam new to JavaScript. When we declare const num = 10 a memory space will be allocated for num and that space holds value 10. when we call it again. console.log(num) how does js knows that num holds the refference to that particular memory address? Are the identifiers also gettting stored in some kind of memory along with theire memory address?

1

There are 1 answers

2
pts On

There are mappings for each scope (e.g. global, local for each funtion call). Each mapping maps variable names to references (pointers) to values.

Example: a = []; b = a; a.push(42); b[0] is 42, because variables a and b are mapped to the same value.