Javascript undefined Type check if a variable has been defined using an equality operator

Description

Javascript undefined Type check if a variable has been defined using an equality operator

var a; // The Variable "a" has been declared but it 
       // hasn't been assigned a definition. 

var b = 5; // The variable "b" has been declared and 
           // assigned the number 5 as it's definition. 

if (a === undefined) { 
   console.log("Variable 'a' is undefined"); 
} else { //from w w  w .ja  va2s .  c  om
   console.log("Variable 'a' is defined"); 
} 

if (b === undefined) {
   console.log("Variable 'b' is undefined"); 
} else { 
   console.log("Variable 'b' is defined"); 
} 



PreviousNext

Related