[JS] Primitive vs Reference Data Types in JavaScript

daniel·2022년 6월 7일
0

[JS]

목록 보기
13/16
post-thumbnail

by Catherine Holecko https://www.verywellfamily.com/best-warm-up-exercises-for-kids-1257044

Primitive data type

In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods or properties. There are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null.

Primitive type 원시타입이란 메소드나 properties가 없으며 순순히 데이터 값을 저장하는 타입이다. numbers, strings, booleans, null, and undefined 등이 있다.

Reference data type

Most of them are considered as objects, and therefore have methods. Examples of such data types include arrays, functions, collections, and all other types of objects.

Reference type 참조타입이란 객체가 저장된 메모리의 주소를 저장하여 그 주소를 참조하는 방식으로 동작되는 타입이다. array, function, object 등이 있다.

Difference between Primitive and Reference

원시타입의 데이터는 콜스택에 저장되며. 콜스택 영역에 해당 데이터 값 자체가 저장됩니다. 변수에 재할당이 일어나면 메모리영역에 저장되어있는 값을 직접적으로 변경한다. 변수에는 값 자체가 저장 되기 때문에 같은 값을 가진 변수를 비교하면 같음 확인 할 수 있다.

참조타입의 데이터 값 자체는 힙메모리에 저장되며 변수에는 그 힙메모리를 가르키는 주소가 저장됩니다. 따라서 같은 데이터 구조와 값으로 이루어진 참조타입 데이터를 만들면 변수에는 주소가 저장되기때문에(각기다른) 비교를 해보았을때 다르다는 것을 알 수 있다.

profile
FE 개발 velog

0개의 댓글