I recently implemented a very simple method to extend the base JavaScript Number Class and tried to call it directly on an entered number in the browser console.
123.myMethod();
But it is not working as expected, it only says: "Invalid or unexpected token"
I was unsure, if I can call Number Methods directly on entered numbers, so I tried standard methods like .toFixed():
123.toFixed(1);
But this also isn't working.
Only if I write a float, I can call Number methods:
123.0.toFixed(1);
It also works, if I put the Integer inside brackets:
(123).toFixed(1);
So my question is: Why are Integers not implicitly casted to Number and why can't I use Number methods on them?