What happens when you instantiate a new object (1) with a parameter in JavaScript?

What happens when you call:

new Object(1)

When I tried, he returned:

[Number: 1]

I want to understand what is happening there. Any information would be appreciated.

+4
source share
2 answers

You can see the specification:

When called new Object(arg), we essentially call ToObject(arg).

ToObject defined as

The abstract ToObject operation converts the argument to a value of type Object according to table 13

And the table says:

Number: returns a new Number object whose inner interval is [[NumberData]]set to the value of the argument. See 20.1 for a description of Number objects.

, new Number(1), .. .


String, Number Boolean , . , , , .. .

:

Boolean(0); // false
Boolean(new Number(0)); // true
+6

constuctor: http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.2.1

Object , :

  • ,
    • Type (value) - Object,
      • ECMAScript, , .
      • -, , , -.
    • Type (value) - String, ToObject ().
    • () , TOObject ().
    • Type (value) - Number, ToObject ().
  • Assert: Null Undefined.
  • obj - ECMAScript.
  • [[Prototype]] obj (15.2.4).
  • [[Class]] obj "Object". [[]] obj true.
  • obj, 8.12.
  • obj.
0

Source: https://habr.com/ru/post/1656002/


All Articles