In JS we often use objects, including numbers, arrays, strings, dates and so on, objects are nothing more than properties and methods of data. objects can be created by constructors (new + normal functions),
var num=new number (value);
var num=number (value), where value is the value of the object
Although sometimes we do not need to do this, we can directly call the corresponding function to achieve the purpose, such as number (), String (), Array (), Boolean (), Date () and so on.
You can do this directly:
var num=number (value)
Inside an object, the property is the property of the constructor itself, not the property of the object defined by the constructor.
For a numeric object, its properties include:
| Properties |
Description |
| Constructor |
Returns a reference to the number function that created this object. |
| Max_value |
The maximum number that can be represented. |
| Min_value |
The smallest number that can be represented. |
| NaN |
Non-numeric value. |
| Negative_infinity |
Negative infinity, which returns this value when overflow. |
| Positive_infinity |
Positive infinity, which returns this value when overflow. |
| Prototype |
gives you the ability to add properties and methods to an object. |
Like it could be used.
var num=number (). MIN VALUE
But it's not going to work that way.
var num=number (1);
var mxnum=num. MAX VALUE
Similarly, the method is the method of the object, not the method of the constructor, that is, the constructor can not invoke the method to perform an action, but should be called through the object method
For a numeric object, its methods include:
| Method |
Description |
| Tostring |
Converts a number to a string, using the specified cardinality. |
| toLocaleString |
Converts a number to a string, using the local number format order. |
| ToFixed |
Converts a number to a string, the result of which has a specified number of digits after the decimal point. |
| Toexponential |
Converts the value of an object to an exponential count method. |
| Toprecision |
Formats the number as the specified length. |
| ValueOf |
Returns the base numeric value of a number object. |
For example, you can use this.
var num=number (123);
var oxnum=num.tostring (16);//Converts the value of a num object to a 16 binary number
Or
var num=123;
var oxnum=num.tostring (16);//JS converts num to a number object and then calls its method
This is also true for other types of objects, not repeating them.
A summary of creating objects in JS