String processing
Call string methods such as toUpperCase() without manually converting a string to a String object.
JS Puzzles · Const
JavaScript primitives can use methods because the language temporarily wraps them in corresponding objects. The primitive remains unchanged; null and undefined are exceptions.
When a property or method is accessed on a primitive, JavaScript can create a temporary wrapper object such as String, Number, or Boolean. The operation uses that wrapper, which is then discarded, so the original value remains a primitive. null and undefined are exceptions because they have no corresponding wrappers.
primitive.method(...arguments)const value = "hello";
console.log(value.toUpperCase());
console.log(typeof value);The string remains a primitive even though JavaScript lets it use methods through a temporary wrapper.
Call string methods such as toUpperCase() without manually converting a string to a String object.
Use number methods such as toFixed() while retaining a numeric primitive.
Understand why primitive values do not retain custom properties assigned through temporary wrappers.
StringNumberBooleanSymbolBigIntString.prototypeNumber.prototypeBoolean.prototype