Javascript undefined Type check if a variable has been declared using typeof()

Description

Javascript undefined Type check if a variable has been declared using typeof()

// The declaration for variable a is commented out, 
// therefore a has not been declared. 

var a, b = 4; /*w ww . j a v a 2 s  .  c o m*/

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



PreviousNext

Related