There's a syntax that Javascript adopted from C where you can perform a logical check, without checking anything:
if (foo) {
}
What is this equivalent to? Is it:
if (foo != null) { }
if (foo !== null) { }
if (typeof(foo) != 'undefined') { }
if (typeof(foo) !== 'undefined') { }
if (typeof(foo) != 'object') { }
if (typeof(foo) !== 'Object') { }
My actual motivation for asking is wanting to ensure that a member "exists" (that is to say, if it is null
or undefined
then it doesn't exist):
if (window.devicePixelRatio !== null)
if (window.devicePixelRatio != null)
if (!(window.devicePixelRatio == null))
if (!(window.devicePixelRatio === null))
if (!(window.devicePixelRatio == undefined))
if (!(window.devicePixelRatio === undefined))
if ((window.devicePixelRatio !== undefined))
My concern is if the member is defined, but defined to be null
, in which case (as far as i'm concerned) it's not assigned.
I know that the expressionless syntax returns true
for a "truthy" value. I'm less interested in a "truthy" value, as an actual value.