How to check for the existence of undeclared variable in js
You can check for the existence of undeclared variable in javascript without getting ReferenceError:
if (x !==undefined){} // gets error if x undeclaredif (x !=='undefined'){} // gets error if x undeclaredif (typeof x !==undefined){} // gets error because typeof x returns "undefined"if (typeof x !=='undefined'){} //right one
No comments:
Post a Comment