This question pertains to the built-in Number object as a primitive wrapper.
let n = new Number(2);
console.log(n); // Number {}
console.log(typeof n); // "object"
n++;
console.log(n); // 3
console.log(typeof n); // "number"
I have observed that JavaScript is automatically performing typecasting in this scenario. Specifically, it is converting the Number
object to a number
primitive. Is there a method to modify the Number object directly without undergoing this type of conversion?