Boxed Types

A primitive data type has no methods or properties. to enable the use of methods on primitives, a mechanism called auto boxing comes into play.

Auto boxing involves automatically converting primitive data types like number, string, and boolean into their respective wrapper objects (Number, String, Boolean) when an object-specific property or method is accessed on them. This allows primitives to temporarily behave like objects with access to additional functionality.

Here’s an example to illustrate auto boxing:

1
console.log((72).toFixed(2)); // 72.00

The boxed type Number can be also expressed as:

1
Number.prototype.toFixed.call(72, 2);