Earlier quoted context omitted.
I wish an empty string was not false. In 'object' terms, an empty string is still a string! It's something. I guess if you think about it from a memory perspective, it's 'nothing'. But since JS is not actually like C, I really wish "" were true.
"" is actually true in C, but that's also because it represents something in memory. Consider how C encodes strings: an empty string is a _pointer_ to a 0 (or a '\0', if you want to think of it as a char). However, the pointer (being an address) is non-zero (since the address 0 is NULL).
Return True to Win
101–110 of 123 posts
Re: Return True to Win
#102Earlier quoted context omitted.
That one isn't specific to Javascript, though. If you can find a mainstream language that doesn't have any values that aren't equal to themselves, I'll give you a cookie. (Going from memory of the last time I tried this challenge, since I can't get it to load at the moment.)
The important property of evaluation is determinism defined by the equality of the output. Classically, id(x) != id(x) is logically inconsistent. Boolean Logic and natural languages are pretty mainstream in my opinion. Do you mean programming languages? If IEEE whatsthenumber is implemented in the FPUs to provide fcmp (Floating-point Compare Instruction), the languages don't have much of a choice. When there are diff…
Equality is domain dependent. For example ∞!=∞ could be justified, as can (0/0)!=(0/0). In the domain of real numbers, equality can be an undecideable problem[1]. I guess the designers of these languages had to choose between tolerable defaults or throwing exceptions. I'm happy with JS doing this:
% node
> 1.0/-0
-Infinity
> 1.0/0
Infinity
> 0/0
NaN
> 0/NaN
NaN
> 1+NaN
NaN
[1] https://math.stackexchange.com/questions/143727/determining-...Re: Return True to Win
#103Earlier quoted context omitted.
So you disagree with the IEEE floating point specification, then? Javascript is directly following spec there.
Does that spec forces you to implement equality test between floating point numbers?
Re: Return True to Win
#104Find the exact combination of browser/OS that does more than show "return true to win" on a white background to win.
Re: Return True to Win
#105This 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.
Re: Return True to Win
#106This table is quite useful to solve some problems: https://dorey.github.io/JavaScript-Equality-Table/
JS gets even weirder when you include all the comparison operators. https://jsfiddle.net/5Yzs6/17/ Did you know undefined is equal to undefined, but not = undefined? Or that two instances of the same object/array are not equal (e.g. [-1] != [-1]), but are both = each other? Or that /.*/ is non-comparable (only != is true) to all numbers, but greater than [-0.5] and "-0.5", and less than [0] and "0"?
Re: Return True to Win
#107This 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.
Re: Return True to Win
#108I typed "true", without the quotes. Did I do it wrong?
Re: Return True to Win
#109Earlier quoted context omitted.
JS gets even weirder when you include all the comparison operators. https://jsfiddle.net/5Yzs6/17/ Did you know undefined is equal to undefined, but not = undefined? Or that two instances of the same object/array are not equal (e.g. [-1] != [-1]), but are both = each other? Or that /.*/ is non-comparable (only != is true) to all numbers, but greater than [-0.5] and "-0.5", and less than [0] and "0"?
Most of the examples you point out make sense if you know that using greater than or less than casts the value to a number. >= and <= always cast their parameters to numbers while == only does if either side is already a number.
By that definition, Brainf*ck[1] also makes sense.