Primitives are the data that are not objects and they have no methods and properties.
All primitives are immutable. They reside in the call stack while execution of the program, unlike the objects that reside in memory heap.
There are seven primitive data types in Javascript
- Number
- String
- Boolean
- Null
- Undefined
- Symbol (ES2015)
- BigInt (ES2020)
Everything in Javascript is either primitive or object
JavaScript only has primitive types and objects.
Primitive types are boolean, null, undefined, bigint, number, string, and symbol.
What differentiates a primitive from an object is that primitives do not have any properties or methods; however, you'll note that 'foo'.toUpperCase() evaluates to 'FOO' and does not result in a TypeError. This is because when you try to access a property or method on a primitive like a string, JavaScript will implicitly wrap the primitive type using one of the wrapper classes, i.e. String, and then immediately discard the wrapper after the expression evaluates. All primitives except for null and undefined exhibit this behaviour.
Top comments (0)