I want to know whether a object is null or undefined so I use the following code:
if(obj==='undefined'||obj===null)
But it doesn't seem to work. Is there similar python type command to get the type of obj in node.js shell? Thanks!
I want to know whether a object is null or undefined so I use the following code:
if(obj==='undefined'||obj===null)
But it doesn't seem to work. Is there similar python type command to get the type of obj in node.js shell? Thanks!
> typeof foo == 'undefined'
true
> typeof 1 == 'number'
true
This should work for you:
if( typeof obj === 'undefined' || obj === null)
From docs:
The
typeof
operator returns a string indicating the type of the unevaluated operand.