Charlie Harvey


Comparison craziness Yeah, because you don't know the difference between equality (==) and strict equality (===) operators, right?

The type of not a number is, well, a number. Sensible. It's a subtype of number.

Well at least that means it ought to be equal to itself, right? Yeah, I agree this is weird, but it's just intended and specified like this in the ECMA specification.

So, what is a string then? String is a primitive type, it's not an object. So the instanceof operator can't be used.

How about a really big number first of all. Wait. What? Hopefully small numbers make more sense. It's a standard float number specified by IEEE 754. You can't expect it will handle so huge numbers. It can't also be precise when counting with decimal numbers, because some of then can't be expressed using the binary system.

I guess not. I bet that max is still bigger than min though. Maximal and minimal numbers can be accessed using the Number.MIN_VALUE and Number.MAX_VALUE. These function return minimal and maximal numbers of the given numbers (using arguments). So for example Math.min(1, 2) gives 1. The algorithm is also using the Infinity number as a maximum value for comparing. That's why Math.min() without arguments return Inifinity. It's its initial value.

Calling + on an empty array and an empty array gives the empty string. Who knew? The plus operator isn't used for concatating arrays. It's used for adding strings and numbers. Deal with it.

An empty object and an empty array gives, ummm, 0. That's not actually and object. {} + [] means empty block and then +[] which converts the empty array to number. However ({} + []) or variable = {} + [] really means what you would expect and returns the same as the example above.

Whereas an empty object and an empty object is not a number. Which is true, I suppose. The same problem. When you have a real expression both are objects and so the result is "[object Object][object Object]".

Ah. It looks like true is equal to one. I’ll just check. Wow, now you discovered the strict equality operator. That means true == 1 will also surprise you?

See if you can work out what this will evaluate to Why would you write anything like this in a real app? Every language supports a simillar bullshit.