in javascript, why people write typeof myvar == "undefined" instead of myvar == undefined?
is compatibility reasons?
this main reason:
if(a == undefined) console.log('test') >> referenceerror: not defined if(typeof == "undefined") console.log('test') >> test but if run comparison:
if(window.a == undefined) console.log('test') >> test so if use a standalone variable can't. using window it's possible, , doesn't matter approach use, stated in comment it's safer use typeof not every variable belongs window scope.
Comments
Post a Comment