impatient-js icon indicating copy to clipboard operation
impatient-js copied to clipboard

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

Open rauschma opened this issue 6 years ago • 6 comments

rauschma avatar Jun 26 '18 16:06 rauschma

Section 13.4 starts:

undefined and null are the two only JavaScript values

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

pabigot avatar Jun 13 '20 16:06 pabigot

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, ''
}

LukasMac avatar Apr 16 '22 18:04 LukasMac

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

rauschma avatar Apr 20 '22 22:04 rauschma

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) { ... }

leonbloy avatar Jul 27 '22 19:07 leonbloy

@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?

yanjankaf avatar Sep 04 '23 17:09 yanjankaf

@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.

bouzlibop avatar Nov 23 '23 11:11 bouzlibop