Why is 4 not an instance of Number?

前端 未结 5 1462
生来不讨喜
生来不讨喜 2020-11-27 03:03

Just curious:

  • 4 instanceof Number => false
  • new Number(4) instanceof Number => true?

Why is this? Same with strings:

5条回答
  •  我在风中等你
    2020-11-27 03:52

    You may try to evaluate:

    >>> typeof("a")
    "string"
    >>> typeof(new String("a"))
    "object"
    >>> typeof(4)
    "number"
    >>> typeof(new Number(4))
    "object"
    

提交回复
热议问题