Tuesday, March 17, 2009

How to find if variable exist or null in javascript ?

When you want to know if the variable is null then you can use :

if ( null == var ) // with type casting
if ( null === var ) // without type casting

When you want to check existance of variable you can use :


if ( typeof var != ‘undefined’ ) // Any scope

No comments: