Posts

Showing posts with the label Primitive vs Non-Primitive Data Types in JavaScript

Primitive Data Types vs Non-Primitive Data Types in JavaScript

Primitive Data Types or Value  Data Types Primitive data types in JavaScript are called "value types" or "primitive types" because they are stored and passed around as actual values, rather than as references to values. Key Characteristics of Primitive Data Types 1. Stored as Actual Values: When you assign a primitive value to a variable, the variable stores the actual value, rather than a reference to the value. 2. Passed by Value: When you pass a primitive value as an argument to a function, the function receives a copy of the original value, rather than a reference to it. 3. Immutable: Primitive values are immutable, meaning they cannot be changed after they are created. Example let x = 5; let y = x; // y receives a copy of the value of x x = 10; // change the value of x console.log(y); // Output: 5 In this example, x and y are assigned the same primitive value, 5. When x is reassigned to 10, y remains unchanged, because it has its own copy of the original value....