What exactly is causing this TypeScript-like expression to log true, true
in JavaScript?
console.log(new Map<String, Number>([]))
If you format it differently, you can see that this might look like TS, but it's just JavaScript. Coincidentally, the angle brackets and the comma match perfectly with the syntax for the two arguments of console.log, where each is a comparison, less than and greater than. What is being compared is:
new Map < String // true
Number > [] // true
Written out in a way that makes this more obvious:
console.log(new Map < String, Number > ([]))
If you meant to write this in a TS file where it might get interpreted (as you may have intended) as a type generic, then you are probably looking for different types: string
and number
, rather than the String
and Number
constructors that you used in the example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With