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

27th Jan 2017, 6:35 AM
Alejandro
Alejandro - avatar
4 odpowiedzi
+ 4
if (x === null)
27th Jan 2017, 6:40 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
I tend to use the opposite to the others here to prevent accidental assignment of null. eg if(null == variable)
27th Jan 2017, 7:23 AM
jay
jay - avatar
+ 1
var x; if(x == null){ console.log("the value is null"); } else { console.log("the value is something else"); }
27th Jan 2017, 7:14 AM
Raheem Kareem
Raheem Kareem - avatar
+ 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 */ }
27th Jan 2017, 8:26 AM
Alex
Alex - avatar