๊ธฐ์ด
๊ฐ์ฒด๋ ์์ฑ์ ์งํฉ์ ๋๋ค. ์์ฑ์ ๊ฐ์ฒด ๋๋ ๊ธฐ๋ณธ ์์๋ฅผ ์ฐธ์กฐ ํ ์ ์์ต๋๋ค. ํ๋ฆฌ๋ฏธํฐ๋ธ๋ ๊ฐ์ด๋ฉฐ ์์ฑ์ด ์์ต๋๋ค.
๋ฐ 5๊ฐ์ ๊ธฐ๋ณธ ์ ํ ์ด์ธ ๊ฒ๋ค์ ๊ฐ์ฒด์ด๋ค.
undefined
null
symbol
ํด๋น ๊ฐ์ฒด์ ์ํด ๋ํ๋ ์ ์์
์ด 6๊ฐ์ง์ ์์ ํ์ ๋ค์ ๋ํด ECMAScript ํ์ค์ Object๋ฅผ ์ ์ํ์ต๋๋ค. Object๋ ๊ฐ๋จํ ํ์๋ฉด ํค-๊ฐ ์ ์ฅ์์ ๋๋ค.
const object = {
key: "value"
}
๊ทธ๋์ ์์ฝํ์๋ฉด, Primitive Type์ด ์๋ ๊ฒ์ Object์
๋๋ค.
๊ทธ๋ฆฌ๊ณ Object๋ผ๋ ๊ฐ๋
์ ํจ์๋ค๊ณผ ๋ฐฐ์ด๋ค๋ ํฌํจํ์ฃ
typeof true; //"boolean"
typeof Boolean(true); //"boolean"
typeof new Boolean(true); //"object"
typeof (new Boolean(true)).valueOf(); //"boolean"
typeof "abc"; //"string"
typeof String("abc"); //"string"
typeof new String("abc"); //"object"
typeof (new String("abc")).valueOf(); //"string"
typeof 123; //"number"
typeof Number(123); //"number"
typeof new Number(123); //"object"
typeof (new Number(123)).valueOf(); //"number"
let hello;
hello // undefined (์ ์ํ์ง ์์)
hello = null; // null ==> null์ด๋ผ๋ ๊ฐ์ ๊ฐ์ง
JavaScript๋ ํ๋ฆฌ๋ฏธํฐ๋ธ์ ๊ฐ์ฒด ์ฌ์ด๋ฅผ ์ฝ๊ฒ ๊ฐ์ ํ๊ธฐ ๋๋ฌธ์ด๋ฉฐ ์ด ๊ฒฝ์ฐ ์์ฑ ๊ธธ์ด์ ์ก์ธ์คํ๊ธฐ ์ํด ๋ฌธ์์ด ๊ฐ์ด ๋ฌธ์์ด ๊ฐ์ฒด๋ก ๊ฐ์ ๋ณํ ๋ฉ๋๋ค.
์ฆ, ํ๋ฆฌ๋ฏธํฐ๋ธ๋ ๊ฐ๊ฐ์ ๊ฐ์ฒด ์์ฑ์๊ฐ ์ ์ํ ๋ชจ๋ ์์ฑ (๋ฉ์๋ ํฌํจ)์ ์ก์ธ์ค ํ ์ ์์ต๋๋ค.
String.prototype.returnMe= function() {
return this;
}
var a = "abc";
var b = a.returnMe();
a; //"abc"
typeof a; //"string" (still a primitive)
b; //"abc"
typeof b; //"object"
++ ์ค๋ช ํด์ฃผ๋ ๊ณณ