1

Lets use the number 22 as an example.

`typeof 22` outputs `number`
`typeof Number(22)` outputs `number`

`Object.prototype.toString.call(22)` outputs `[object Number]`
`Object.prototype.toString.call(Number(22))` outputs `[object Number]`


`22 === Number(22)` outputs `true`

`if(22.toString() === "22") { console.log(true) }` throws `SyntaxError: Invalid or unexpected token`
`if(Number(22).toString() === "22") { console.log(true) }` outputs `true`

Why this difference in behaviour? I understand that you cannot use numerics as variable names, but I am trying to use it as an immediate value.

Ayush Gupta
  • 8,716
  • 8
  • 59
  • 92

0 Answers0