> Given that the above works in the browser, what exactly is it doing?
Oh, buckle up!
new DOMPoint<Number>(4,5)
Let's first clean things up a bit: DOMPoint an Number are just identifiers. So, let's replace those with a and b:
new a<b>(4,5)
Let's also add some spacing around these tokens to distinguish them better:
new a < b > (4, 5)
Yep, those < and > are comparison operators.
And let's also add some parentheses to make clear the order of operations in these comparisons. The above expression is equivalent to:
(new a < b) > (4, 5)
Now, let's remember that a is DOMPoint, so `new a` is just instantiating a new DOMPoint object. Yep, the parentheses at the end of the `new Something` calls are optional if no parameters are passed.
> new DOMPoint
DOMPoint { x: 0, y: 0, z: 0, w: 1 }
(That's the result of trying that out on a JS console. The initial > on the first line is the REPL prompt, not part of the JS syntax. And the second line is what the REPL prints.)
So the < operator is comparing a DOMPoint object to b, which is Number, which is just a constructor function. IIRC, what JS does is these kind of situations is to convert both operands to strings and then compare those.
> (new DOMPoint).toString()
"[object DOMPoint]"
> Number.toString()
"function Number() {
[native code]
}"
So the first < comparison is going to compare these two strings, and since '[' is less than 'f' (of course... ASCII), the < result will be `true`. The whole expression can then be reduced to:
true > (4, 5)
The right-hand side of this > operation, `(4, 5)`, is curious. The parentheses are just normal parentheses for grouping expressions, but what's inside of them are two expression joined together by the comma operator[1]! Basically, both expressions, 4 and 5, are evaluated, one after the other, and the result of the whole is the result of the last one:
> 4, 5
5
So, we're almost there! The whole thing can now be reduced to:
true > 5
Since one of the operands is a number, JS tries to convert the other one to a number too. `true` converted to a number yields 1, which is not bigger than 5 — finally, something that makes sense!
So now we know why the whole thing that looks like TypeScript but isn't, is valid JavaScript and evaluates to false :)
> new DOMPoint<Number>(4,5)
false
1:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...