0
Does anyone here know about null checks ?
use and if statement to log " the value is null" to the console if result equals null, or "the value is something else " if result does not equal null
4 Réponses
+ 4
if (x === null)
+ 2
I tend to use the opposite to the others here to prevent accidental assignment of null.
eg
if(null == variable)
+ 1
var x;
if(x == null){
console.log("the value is null");
} else {
console.log("the value is something else");
}
+ 1
if (x != null) continue;
log.("value isn't null")
else { log.("value is null or other value"} };
You can easily invert it,
if (x == null)
log("value is null");
else
log("value isn't null");
I just saw the tag was #ecma sorry but the logic is almost the same.
You can do it like this;
if( typeof somevar !== 'undefined' ) {
/* ecma evaluators include
* null
*undefined
*NaN
*empty string ("")
*0
*false
*/
}