Live data from Hacker News

Return True to Win

alf.nu

61–70 of 123 posts

Re: Return True to Win

#63

Does anybody really know why JS's type system was designed the way it was? It seems so out of whack with what people want out of a language, dynamically typed or otherwise.

It wasn't; the language was implemented from scratch in ten days.

That explains a lot. Source for others that are interested: https://www.w3.org/community/webed/wiki/A_Short_History_of_J...

Re: Return True to Win

#66
post #21

This table is quite useful to solve some problems: https://dorey.github.io/JavaScript-Equality-Table/

> Moral of the story: Always use 3 equals unless you have a good reason to use 2. NaN === Nan // => false [] === [] // => false {} === {} // => false [1] === [1] // => false [0] === [0] // => false I guess i never see the gains in the triple vs double equal sign wars.

None of those are true when using `==` either.

The NaN example comes directly from IEEE754

The others are based on the fact that the two sides are not referring to the same object. C "equivalents" of your examples:

    int x[0], y[0]; x == y; // false
    typedef struct {} empty_t; empty_t *x, *y; x == y; // false
    int x[] = { 1 }, y[] = { 1 }; x == y; // false
    int x[] = { 0 }, y[] = { 0 }; x == y; // false

Re: Return True to Win

#67

Earlier quoted context omitted.

It loads eventually

Does it? ReturnTrue:1 Fetch API cannot load https://bigger.alf.nu/db/true/H5VmsyVCBD62113H5Slu . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://alf.nu' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

it does

Re: Return True to Win

#69

Earlier quoted context omitted.

> Moral of the story: Always use 3 equals unless you have a good reason to use 2. NaN === Nan // => false [] === [] // => false {} === {} // => false [1] === [1] // => false [0] === [0] // => false I guess i never see the gains in the triple vs double equal sign wars.

Do any of those return true if you use double equals? The distinction only really comes up when you have to different types on either side and then It will coerce one of the types to match the other.

That is correct. The canonical example is string-numeric coercion:

    "0" == 0 && "0" !== 0

Re: Return True to Win

#70
post #56

Does someone have a <52 char solution for the counter one ?

(x=0)=>()=>++x

You can save one character by doing this:

(x=0)=>_=>++x

the underscore is another variable but a single variable does not require parenthesis. So instead of two chars for the two parens, you use a single char for a single letter variable. JS FTW ;)

Post reply on HN