Blog from an ATG Developer

April 22, 2009

Java Script – Check whether a particular variable is defined or not

Filed under: Java Script, Learning — madhulal @ 7:05 am

Yesterday I came across a situation in my project which demands whether a js variable exists or not.The following is the solution for that.

if(typeof varName != ‘undefined’){

alert(“variable exists”);

}

Refernce : https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/typeof_Operator

Blog at WordPress.com.