Undefined

Execution Context –

1st phase (Creation) –

– Global Obj
– this
– Outer Environment
– Hoisting – functions are in memory, variables names are valid, but undefined

output:

undefined

undefined

In JS, when we see undefined, its a special value that JS has which means the variable has not been set.

output:


a is undefined!

In the example below, you’ll get an error sayings its variable a is ‘not defined’ because after the JS compiler parses everything and put them into memory, it didn’t find anything for a variable named ‘a’.

Thus, when you try to access it in your execution phase, a does not exist.

Never set yourself to ‘undefined’

It’s better to let ‘undefined’ mean that the variable has NEVER been set. It should mean the developer has never touched it.