[Core Javascrpt] 01. Data type

IT/Web Programming|2023. 6. 19. 17:00

Data type, execution context, scope, hoisting,call back, this , closure, prototype ,class 



Fundamental of Javsctript

Any knowledge important from ES5 and still used in ES6.

01. Data type

Primitive Type / Reference Type

 

Javascript :

Stack memory  - Primitive Type  ,
/ heap memory  - Reference type 


Var a ; => 

when you update the a = 'abcdef' 
then it will write in some where else not 5004 and and update in 1003 

Similar to the object, (reference type )  (one more process
it will store multiple memory addresses. 

one extra memory 


Primitive : it will change the memory value when you update the value of the variable. 
Refrence:  it wont change the memory because it has one more extra 


If it save the memory address :

slow in data 
more efficient 
 

In JavaScript, an "immutable value" refers to a value that cannot be changed once it is created. Immutable values in JavaScript include primitive data types such as numbers, strings, booleans, null, undefined, and symbols.

Once an immutable value is created, its value cannot be modified. If you want to change the value, you need to create a new value. For example, when working with strings, you cannot directly modify the existing string. Instead, you create a new string with the desired changes.

Immutable values : string,numbers,booleans

Copy : 

copy of primitive vs copy of reference 

copy of array  will result in changing the original value 

Immutable values, such as numbers, strings, booleans, null, undefined, and symbols, cannot be changed once they are created. When you update the value of a variable storing an immutable value, it will change the memory value. To modify an immutable value, you need to create a new value.

On the other hand, mutable values, such as objects and arrays, can be modified directly. When you assign a mutable value to a variable, it actually stores a reference to the value's memory address. Modifying the value through the reference does not change the memory address itself. This is why modifying a mutable value does not require creating a new value.

In summary, primitive data types store the actual value directly in the variable's memory space, while reference data types store a memory address (reference) pointing to the actual data in memory. Understanding this distinction is crucial for managing and manipulating data correctly in JavaScript.

반응형

댓글()