Re: Why Number(symbol) crashes?
whoops, sorry, I missed the earlier thread. disregard. On Tue, Oct 11, 2016 at 5:53 PM, Jordan Harbandwrote: > I'm not sure what you're asking. `Number(Symbol())` throws a TypeError. > > Perhaps are you using a Symbol sham (that only partially is able to > polyfill Symbols)? > > In what browser/engine are you seeing `NaN`? > > On Tue, Oct 11, 2016 at 11:37 AM, Raul-Sebastian Mihăilă < > raul.miha...@gmail.com> wrote: > >> How is NaN useful? Isn't it better to be explicit if you really want a >> string? >> >> ___ >> es-discuss mailing list >> es-discuss@mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Why Number(symbol) crashes?
I'm not sure what you're asking. `Number(Symbol())` throws a TypeError. Perhaps are you using a Symbol sham (that only partially is able to polyfill Symbols)? In what browser/engine are you seeing `NaN`? On Tue, Oct 11, 2016 at 11:37 AM, Raul-Sebastian Mihăilă < raul.miha...@gmail.com> wrote: > How is NaN useful? Isn't it better to be explicit if you really want a > string? > > ___ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Why Number(symbol) crashes?
How is NaN useful? Isn't it better to be explicit if you really want a string? ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Why Number(symbol) crashes?
In my opinion it's a bit incoherent that each object-coercible type behaves differently when coercing symbols to it. Symbols can be explicitly coerced to strings, but not implicitly: ```js String(Symbol("abc")); // "Symbol(abc)" Symbol("abc") + ""; // TypeError ``` Symbols can't be coerced to numbers, neither explicitly nor implicitly: ```js Number(Symbol("abc")); // TypeError +Symbol("abc"); // TypeError ``` Symbols can be coerced to booleans, both explicitly and implicitly: ```js Boolean(Symbol("abc")); // true !!Symbol("abc"); // true ``` Maybe the `Number` constructor could behave analogous to `String` and return `NaN` for symbols, instead of calling ToNumber. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Why Number(symbol) crashes?
Symbol is such an oddball; similar to this if you do Symbol() + "" it will also throw an exception unlike all other built-ins. Granted I have no idea what a string representation of Symbol *really* would be but no other built in type behaves the way Symbol does. I do think Number(Symbol()) should return NaN though. I'd like to know why this didn't happen. On Tue, Oct 11, 2016 at 2:07 AM, medikoowrote: > I was searching the archived but wasn't able to find the answer. > > What's the reasoning behind having Number(symbol) crash instead of > returning > NaN (as it's in case all other non-coercible values?). It feels not > consistent. > > If someone can point me to some discussion that provided the reasoning I'd > be grateful > > > > -- > View this message in context: http://mozilla.6506.n7.nabble. > com/Why-Number-symbol-crashes-tp359554.html > Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at > Nabble.com. > ___ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Why Number(symbol) crashes?
I was searching the archived but wasn't able to find the answer. What's the reasoning behind having Number(symbol) crash instead of returning NaN (as it's in case all other non-coercible values?). It feels not consistent. If someone can point me to some discussion that provided the reasoning I'd be grateful -- View this message in context: http://mozilla.6506.n7.nabble.com/Why-Number-symbol-crashes-tp359554.html Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss