rauschma / exploring-js

20 stars 0 forks source link

Chapter: The non-values `undefined` and `null` #9

Open rauschma opened 6 years ago

pabigot commented 4 years ago

Section 13.4 starts:

undefined and null are the two only JavaScript values

should be "...only two..."

LukasMac commented 2 years ago

Section 14.3

Maybe also good to mention falsy value from Bigint 0n?

if (x) { // truthy?
  // x is neither: undefined, null, false, 0, NaN, ''
}

as well in this example:

if (!x) { // falsy?
  // x is: undefined, null, false, 0, NaN, ''
}
rauschma commented 2 years ago

@LukasMac Good catch, thanks! This will be fixed in the next release.

leonbloy commented 2 years ago

I find strange that in the section

Is x either undefined or null?

only the natural/trivial comparison is mentioned

if (x === undefined || x === null) { ... }

and not the equivalent and terser alternative

if (x == null) { ... }

yanjankaf commented 1 year ago

@leonbloy Yes, you make a good point, I think we can also use the x== null as null == undefined to check if x is either undefined or null. @rauschma I wonder whats wrong in here?

bouzlibop commented 11 months ago

@leonbloy, @yanjankaf take a look at this section: 13.4.3.2 Use case for ==: comparing with undefined or null for the explanation of why if (x == null) { ... } is not preferred.