({}).toString.call(Number.prototype) === "[object Number]"
The Number prototype object is itself a Number object (its [[Class]] is "Number") whose value is +0.
Why would it be useful for Number.prototype
to be a Number? (the same goes for every other built-in prototype which has the [[Class]] set to not Object)
I'm picking on Number.prototype
specifically because I can imagine sensible legacy reasons for Array.prototype
and Date.prototype
.
Definition and Usage. prototype allows you to add new properties and methods to numbers. prototype is a property available with all JavaScript objects.
Javascript Number() Function object: This parameter holds the objects that will be converted any type of javascript variable to number type. Return Values: Number() function returns the number format for any type of javascript variable. Example 2: Not a number is returned by the compiler.
The toString() method in Javascript is used with a number and converts the number to a string. It is used to return a string representing the specified Number object. The toString() method is used with a number num as shown in the above syntax using the '.
Number is a primitive wrapper object used to represent and manipulate numbers like 37 or -9.25 . The Number constructor contains constants and methods for working with numbers.
In general, Constructor.prototype
is an exemplar of the "type" defined by Constructor
. Although things seem to get hairy for immutable primitives, and especially once you involve the boxing stuff, this exemplar concept still makes sense, with 0
being the "exemplar" of Number
.
The Number prototype object is itself a Number object (its [[Class]] is "Number") whose value is +0
Why wouldn't Number.prototype
be a Number object? Its [[Prototype]]
is Object.prototype, so it still inherits from Object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With