数字和数字对象有什么区别? [英] What is the difference between a number and a number object?
本文介绍了数字和数字对象有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
存储在普通变量中的数字之间有什么区别:
What is the difference between a number stored in a normal variable:
var foo = 5;
还有一个数字对象:
var bar = new Number(5);
我可以使用数字对象吗?
What can I use a number object for?
推荐答案
数字
对象包含一些有用的方法和属性,例如:
A Number
object contains some useful methods and properties such as:
Method Description
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
toExponential(x) Converts a number into an exponential notation
toFixed(x) Formats a number with x numbers of digits after the decimal point
toPrecision(x) Formats a number to x length
toString() Converts a Number object to a string
valueOf() Returns the primitive value of a Number object
数字对象属性
Number Object Properties
Property Description
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
constructor Returns the function that created the Number object's prototype
MAX_VALUE Returns the largest number possible in JavaScript
MIN_VALUE Returns the smallest number possible in JavaScript
NEGATIVE_INFINITY Represents negative infinity (returned on overflow)
NaN Represents a "Not-a-Number" value
POSITIVE_INFINITY Represents infinity (returned on overflow)
prototype Allows you to add properties and methods to an object
这篇关于数字和数字对象有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文