Primitive
In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods. There are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null.
Most of the time, a primitive value is represented directly at the lowest level of the language implementation.
All primitives are immutable, i.e., they cannot be altered. It is important not to confuse a primitive itself with a variable assigned a primitive value. The variable may be reassigned a new value, but the existing value can not be changed in the ways that objects, arrays, and functions can be altered.
Example
// Using a string method doesn’t mutate the string var bar = “baz”; console.log(bar); // baz bar.toUpperCase(); console.log(bar); // baz
// Using an array method mutates the array var foo = []; console.log(foo); // [] foo.push(“plugh”); console.log(foo); // [“plugh”]
// Assignment gives the primitive a new (not a mutated) value bar = bar.toUpperCase(); // BAZ
Non-primitive data types
The data types that are derived from primitive data types of the JavaScript language are known as non-primitive data types. It is also known as derived data types or reference data types.
Objects and arrays are referece types.
Use the share button below if you liked it.
It makes me smile, when I see it.