Number.isNaN

Sam Tobin-Hochstadt samth at ccs.neu.edu
Fri Dec 14 05:08:12 PST 2012


On Fri, Dec 14, 2012 at 2:43 AM, Andreas Rossberg <rossberg at google.com> wrote:
> On 14 December 2012 06:46, John-David Dalton
> <john.david.dalton at gmail.com> wrote:
>>Axel Rauschmayer:
>>> Honest question: I have yet to see boxed values in practice. Are there any
>>> real use cases?
>>
>> See Modernizr:
>> https://github.com/Modernizr/Modernizr/blob/master/feature-detects/video.js#L23
>
> I think not. And wrapping bools, like the above piece of code does, is
> a particularly bad idea, because JS says
>
>   (Object(false) ? 1 : 2)  ===  1

Fortunately, I think that bit of code never returns Object(false),
because the `if` fails first, and just plain `false` is returned.

Really, since objects are truthy, `new Boolean(bool)` there could be
replaced with `{}`.  Or, the whole body of the `if` could just be an
object literal.

Sam


More information about the es-discuss mailing list