Other than creating a function, is there a shorter way to check if a value is undefined
,null
or false
only in JavaScript?
Another solution:
Based on the document, Boolean object will return true if the value is not 0, undefined, null, etc. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
If value is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.
So
if(Boolean(val)) { //executable... }