Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Assigning local reference to global

here's what I can't understand.

I have this function here

function foo(){
let a = {a:1};
window.a = a; 
}

as you can see, this assign to a an object, so a reference to it, and then it creates a new property on the window object that contains this reference. If the a variable is local, it's reference point to an address in the stack, so, how can I access a from window, also out of the function, when the stack is cleaned?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If the a variable is local, it's reference point to an address in the stack

No. While a variable might be allocated on a stack containing the reference, what it references (the object) is likely allocated on "the heap", as - as you've noticed - it's lifetime is not known and as such must be managed by the garbage collector and cannot be stack-allocated.

That said the "stack" vs. "heap" distinction is not quite reflecting the reality of modern JIT-compilers.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!