In addition to using Primitive for Number, we can use Primitive Wrapper Object to wrap Number.
Version
ECMAScript 2015
typeof
let x = 1
let y = new Number (1) // ?
typeof x // ?
typeof y // ?
x
is Number Literaly
is a Wrapper Object for Numbertypeof
:- Number Literal :
number
- Wrapper Object :
object
- Number Literal :
instanceOf
let x = 1
let y = new Number (1) // ?
x instanceof Number // ?
y instanceof Number // ?
instanceof
:
- Number Literal :
false
- Wrapper Object :
true
valueOf
let x = 1
let y = new Number (1) // ?
x === y.valueOf () // ?
We can use valueOf
to unwrap Wrapper Object.
Number
let x = 1
let y = new Number (1) // ?
x === Number (y) // ?
We can also use Number
to unwrap Wrapper Object.
Dynamic Property
let x = 1
let y = new Number (1) // ?
y.id = 2
y // ?
y.id // ?
Since Wrapper Object is an Object, we can add a new property to Primitive Wrapper Object.
Conclusion
- Primitive Wrapper Object is immutable. We can’t modify the inner value of Wrapper Object