search

Home  >  Q&A  >  body text

javascript - Will variables defined as undefined in JS occupy memory?

let x = {
    'a' = 123
}

let y = {
    'a' = 123,
    'b' = undefined
}
let z = undefined;

如上,y会比x占用内存多么,z会占用内存么?
ringa_leeringa_lee2791 days ago895

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:16:18

    undefined occupies memory, has a fixed size, and is stored in the stack area, so z occupies memory. xy objects exist in the heap area, and their memory addresses are stored in stack memory. Because y has more undefined, it occupies more heap memory than x.

    reply
    0
  • Cancelreply