DEV Community

Lukas Gaucas
Lukas Gaucas

Posted on

undefined vs. null in JS – don't get confused

javascript newbies often confuse undefine with null :

  • undefined means a program (process) has never heard of that i.e. no address to memory assigned , unless it's an error due to scoping ;

  • null means a program (process) assigned an address to a variable in-memory , but variable refers to nothing (null) . A real life example for null would be :

    imagine you take a taxi from airport to your home address visible on Google maps, but when you get to the place you find your house on wheels transferred, only plane pavement left – the pavement still has the address (you somehow got lifted by a taxi driver tho), but it's null i.e. none of house on wheels (data structure) left .

REMEMBER : variables are just references to the actual data structure[s] with it's own address[es] in-memory too .

Top comments (0)