tc39 / proposal-optional-chaining

https://tc39.github.io/proposal-optional-chaining/
4.94k stars 75 forks source link

Optional exclusion (`undefined` case) #130

Closed guigaoliveira closed 4 years ago

guigaoliveira commented 4 years ago

In the readme we have to

delete a?.b
a == null ? true : delete a.b

but we know that

delete undefined // false
delete null // true 

shouldn't it be like this?

delete a?.b
a == null ? false : delete a.b
rkirsling commented 4 years ago

delete undefined is false because it's an attempt to delete the global property called "undefined"; delete void 0, which attempts to delete the value undefined, is true.

When a is nullish, delete a?.b applies the delete operator to the value undefined, hence it's true.

guigaoliveira commented 4 years ago

Got it, thanks!