데이터 타입
1. 원시데이터타입과 객체
1-1. 원시(기본) 데이터 타입(Primitive Data Type)
객체가 아닌 데이터 타입
Number(숫자)
String(문자)
Boolean
Null
Undefined
Symbol(ES6에서 추가됨)
Property나 Method가 오지 않음
1-2. 객체 데이터 타입(참조 데이터 타입)
원시 데이터 타입외의 모든 데이터 타입들은 객체임
Object
2. 레퍼 객체(Wrapper Object)
문자열과 관련해서 필요한 기능성을 객체지향적으로 제공해야 하는 경우, 원시 데이터 형을 객체처럼 다룰 수 있도록 자바스크립트 내부적으로 만들어진 객체
즉, 레퍼객체는 객체화 된 원시데이터를 의미
String
Number
Boolean
(null과 undefined는 레퍼 객체가 존재하지 않음)
var str = 'coding';
//1열의 내용은 var str = new String('coding'); 과 같은 내용
console.log(str.length); // 6
console.log(str.charAt(0)); // "C"
var str = 'coding';
str.prop = 'everybody';
//1. str.prop 하는 순간 내부적으로 String 객체가 만들어짐
//2. prop 프로퍼티는 이 객체에 저장되고 이 객체는 곧 제거 됨
//3. 따라서, prop이라는 속성이 저장된 객체는 존재하지 않게 됨
console.log(str.prop); // undefined
Last updated
Was this helpful?