What Is Primitive Data Types

What Is Primitive Data Types

In JavaScript, primitive is data that is not an object and has no methods. There are 7 primitive data types is string, number, bigint, boolean, undefined, symbol, and null, What Is Primitive Data Types

All primitives are immutable, they cannot be altered. 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.

Except for null and undefined, all primitive values have object equivalents that wrap around the primitive values

Example : Primitive Data Types

Below example will help you to understand that primitive data values are immutable and it’s original value can’t altered.

// Using a string method doesn't mutate the string
Var codeA = "codeA";
console.log(codeA );               // codeA 
console.log(codeA);               // codeA 

//Here only Assignment gives the primitive a new value
  codeA = codeA.toUpperCase();       // CODEA

//When we are Using an array method mutates the array
var codeB = [];
console.log(codeB);               // []
console.log(codeB);               // ["codeC"]


Leave a Reply

Your email address will not be published.