Does anyone here know about null checks ? | Sololearn: Learn to code for FREE!


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

1/27/2017 6:35:21 AM


4 Answers

New Answer



I tend to use the opposite to the others here to prevent accidental assignment of null. eg if(null == variable)


var x; if(x == null){ console.log("the value is null"); } else { console.log("the value is something else"); }


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 */ }