flowforfrank / webtips

https://webtips.dev
1 stars 0 forks source link

javascript-type-conversion #27

Open utterances-bot opened 11 months ago

utterances-bot commented 11 months ago

Why +(!![]+!![]+!![]+!![]+[!![]+!![]]) yields 42? - Webtips

JavaScript can produce the most unexpected results at times. For example, you may have heard before that NaN is not equal to NaN. But why is that?

https://webtips.dev/javascript-type-conversion

octavian-nita commented 11 months ago

Hi Ferenc,

The part that reads "The unary plus operator that precedes the empty array, will try to convert its operand into a number if it isn’t already one. Falsy values will result in 0. For example, +false or +'' are also evaluated to 0. Just like +[]" seems to suggest that an empty array is a falsy value in JavaScript. I don't believe this to be true, at least based on what the MDN (and not only) says: https://developer.mozilla.org/en-US/docs/Glossary/Falsy.

Anyway, an interesting dive in, your article!