JavaScript ์ •๋ฆฌ

jeongjwonยท2023๋…„ 3์›” 6์ผ
0

SEB FE

๋ชฉ๋ก ๋ณด๊ธฐ
15/56

๐Ÿ“Œ let vs const

const ๋ณ€์ˆ˜๋Š” ํ•ญ์ƒ ์žฌํ• ๋‹น ๊ธˆ์ง€ , ๋ฐฐ์—ด ๋˜ํ•œ ์žฌํ• ๋‹น ๊ธˆ์ง€ํ•˜๋‚˜ ์ƒˆ๋กœ์šด ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์‚ญ์ œ ๊ฐ€๋Šฅ, ๊ฐ์ฒด ๋˜ํ•œ ์žฌํ• ๋‹น ๊ธˆ์ง€ํ•˜๋‚˜ ์ƒˆ๋กœ์šด ์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์‚ญ์ œ๊ฐ€๋Šฅ

const constNum = 0;
constNum = 0; //Uncaught TypeError: Assignment to constant variable. ์žฌํ• ๋‹น๋˜์–ด ์—๋Ÿฌ ๋ฐœ์ƒ

const arr = []
const pushNum = 42;
arr.push(pushNum); //1 = arr.length
arr[0] = 42;
arr[1] = 3; // Uncaught TypeError: Assignment to constant variable. ์žฌํ• ๋‹น๋˜์–ด ์—๋Ÿฌ ๋ฐœ์ƒ

const obj = { x:1 };
obj.x = 1;
delete obj.x; 
obj = { x: 123 }; // Uncaught TypeError: Assignment to constant variable. ์žฌํ• ๋‹น๋˜์–ด ์—๋Ÿฌ ๋ฐœ์ƒ

๐Ÿค” ์žฌํ• ๋‹น๋„ ์•ˆ๋˜๋Š”๋ฐ ์™œ const ํ‚ค์›Œ๋“œ๋ฅผ ์“ฐ๋Š๋ƒ?
https://google.github.io/styleguide/jsguide.html#features-use-const-and-let


๐Ÿ“Œ Scope ์Šค์ฝ”ํ”„ & Closure ํด๋กœ์ €

๋ณ€์ˆ˜์˜ ๊ฐ’์„ ์ฐพ์„ ๋•Œ ํ™•์ธํ•˜๋Š” ๊ณณ

  1. ํ•จ์ˆ˜ ์„ ์–ธ์‹๊ณผ ํ•จ์ˆ˜ ํ‘œํ˜„์‹
	let funcExpressed = 'to be a function';
	
	function funcDeclared(){
      return 'this is a function declaration';
    }
	funcExpressed = function(){
      return 'this is a function expression';
    }
	console.log(typeof funcDeclared);//'function'
	console.log(typeof funcExpressed); //'string'

	const funcContainer = { func : funcExpressed }; 
	//๊ฐ์ฒด๋ฅผ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•˜์—ฌ ๋‹ค์‹œ ํ•œ ๋ฒˆ funcExpressed ํ•จ์ˆ˜ ์‹คํ–‰
	console.log(funcContainer.func()); 
	//'this is a function expression' 

	funcContainer.func = funcDeclared;
	//๊ฐ์ฒด์˜ func ๊ฐ’์„ funcDelcared ํ•จ์ˆ˜๋กœ ๋ณ€๊ฒฝ
	console.log(funcContainer.func()); 
	// 'this is a function declaration'

ํ˜ธ์ด์ŠคํŒ…

  1. lexical scope
	let message = 'Outer'; // ์ „์—ญ๋ณ€์ˆ˜ Global
	function getMessage() { return message; }
	function shadowGlobal(){ 
      let message = 'Inner'; // ์ง€์—ญ ๋ณ€์ˆ˜ 
      return message; 
    }
	function shadowGlobal2(message){ return message; }
	function shadowParameter(message){ 
      message = 'Do not use parameters like this!; 
      return message;
    }

	console.log(getMessage()); // 'Outer' === message
	console.log(shadowGlobal()); // ๋ณ€์ˆ˜๋ช…์ด message๋กœ ์ „์—ญ, ์ง€์—ญ์œผ๋กœ ๋™์ผํ•˜์ง€๋งŒ ๋‚ด๋ถ€ ์Šค์ฝ”ํ”„์—์„œ๋Š” ์ง€์—ญ๋ณ€์ˆ˜๊ฐ€ ๋” ์šฐ์„ ์ด๋ฏ€๋กœ 'Inner' ์ถœ๋ ฅ
	console.log(shadowGlobal2('Parmeter')); // ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์€ ๊ฐ’์ด ํ˜ธ์ถœ 'Parameter'
	console.log(shadowParameter('Parameter')); // ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์€ ๊ฐ’์„ ์žฌํ• ๋‹นํ•˜์—ฌ ์žฌํ• ๋‹นํ•œ ๊ฐ’์„ ํ˜ธ์ถœ 'Do not use parameters like this!'
	console.log(message); //์–ด๋– ํ•œ ๋‚ด๋ถ€ ์Šค์ฝ”ํ”„๋ฅผ ๊ฑฐ์น˜์ง€ ์•Š๊ณ  ์™ธ๋ถ€ ์Šค์ฝ”ํ”„์˜ ์ „์—ญ ๋ณ€์ˆ˜๋กœ ์ถœ๋ ฅ 'Outer'
  1. default parameter
	function defaultParmeter(num = 5){ return num; }
	console.log(defaultParameter()); // ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์–ด๋– ํ•œ ๊ฐ’๋„ ์ง€์ •ํ•˜์ง€ ์•Š์•˜์œผ๋ฏ€๋กœ default ๊ฐ’์œผ๋กœ 5 ํ˜ธ์ถœ
	console.log(defaultParameter(10)); // ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ 10์œผ๋กœ ์ง€์ •ํ–ˆ์œผ๋ฏ€๋กœ default ๊ฐ’์ด ์•„๋‹Œ ๋งค๊ฐœ๋ณ€์ˆ˜์ธ 10 ํ˜ธ์ถœ

	function pushNum(num, arr = []){//๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ˆซ์žํ˜• ์ธ์ž์™€ ๋ฐฐ์—ดํ˜• ์ธ์ž
      arr.push(num);
      return arr;
    }
	console.log(pushNum(10)); 
	//๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ˆซ์žํ˜• ์ธ์ž๋งŒ ๋“ค์–ด์™”์œผ๋‹ˆ default ๊ฐ’์œผ๋กœ ๋‘๋ฒˆ์งธ ์ธ์ž์ธ ๋ฐฐ์—ด์€ ๋นˆ ๋ฐฐ์—ด์„ ๊ฐ€๋ฆฌํ‚จ๋‹ค. ๋”ฐ๋ผ์„œ ๋นˆ๋ฐฐ์—ด์— 10 ์„ push ํ•˜์—ฌ [10] ๋ฐ˜ํ™˜
	console.log(pushNum(20)); //[20] ๋ฐ˜ํ™˜
	console.log(pushNum(4,[1,2,3]); 
    //๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๋‹ค ๋“ค์–ด์™”์œผ๋ฏ€๋กœ ํ•ด๋‹น ๋ฐฐ์—ด์— ์ˆ˜๋ฅผ pushํ•˜๋ฉด [1,2,3,4] ๋ฐ˜ํ™˜
  1. ํด๋กœ์ €
    ํ•จ์ˆ˜๊ฐ€ ์„ ์–ธ๋œ ์–ดํœ˜์  ํ™˜๊ฒฝ
    ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜๋Š” ํ™˜๊ฒฝ๊ณผ๋Š” ๋ณ„๊ฐœ๋กœ ๊ธฐ์กด์— ์„ ์–ธ๋˜์–ด ์žˆ๋˜ ์–ดํœ˜์  ํ™˜๊ฒฝ์„ ๊ธฐ์ค€์œผ๋กœ ๋ณ€์ˆ˜๋ฅผ ์กฐํšŒ
    ํด๋กœ์ € ํ•จ์ˆ˜ = ์™ธ๋ถ€ํ•จ์ˆ˜์˜ ๋ณ€์ˆ˜์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๋‚ด๋ถ€ํ•จ์ˆ˜

function factories
namespacing private variables/functions

	function increaseBy(increaseByAmount){
      return function(numberToIncrease){//์ปค๋ง
        return numberToIncrease + increaseByAmount;
      }
    }
	const increaseBy3 = increaseBy(3); 
	const increaseBy5 = increaseBy(5);
	//๋งค๊ฐœ๋ณ€์ˆ˜ increaseByAmount๋ฅผ ์†Œ๊ด„ํ˜ธ ์•ˆ์˜ ์ˆซ์ž์ด๋ฉฐ ํ•จ์ˆ˜ ๋‚ด ์ฒซ๋ฒˆ์งธ ์ปค๋งํ•จ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€๋งŒ ๋งค๊ฐœ๋ณ€์ˆ˜์ธ numberToIncrease๋Š” ๋ฏธ์ •

	console.log(increaseBy3(10)); // increaseByAmount = 3 , numberToIncrease = 10 => 3 + 10 = 13
	console.log(increaseBy5(10)); // increaseByAmount = 5 , numberToIncrease = 10 => 5 + 10 = 15
	//์œ„์—์„œ ์ง€์ •ํ•œ ๋ณ€์ˆ˜๋“ค์—๊ฒŒ ๋งค๊ฐœ๋ณ€์ˆ˜ numberToIncrease ๋ฅผ ์ง€์ •ํ•ด์คŒ

	console.log(increaseBy(8)(6) + increaseBy(5)(9)); // ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜์ง€ ์•Š๊ณ ๋„ ์ „์ฒด ํ”„๋กœ์„ธ์Šค๋ฅผ ์ง„ํ–‰์‹œ์ผœ ๊ฒฐ๊ณผ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์Œ ( 8 + 6 ) + ( 5 + 9 ) = 14 + 14 = 28
  1. lexical scope + ํด๋กœ์ €
	let age = 27; //global
	let name = 'jin'; //global
	let height = 179; //global
	
	function outerFn(){
      let age = 24; //let ์œผ๋กœ ์žฌ์„ ์–ธํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— global age ์™€๋Š” ๋ฌด๊ด€
      name = 'jimin'; //global ๋ณ€์ˆ˜๋ฅผ ์žฌํ• ๋‹น
      
      function innerFn(){
        age = 26; //innerFn ์™ธ๋ถ€์ด์ž outerFn ๋‚ด๋ถ€ ์Šค์ฝ”ํ”„์˜ age ๋ฅผ ์žฌ ํ• ๋‹น
        let name = 'suga'; //let ์œผ๋กœ ์žฌ์„ ์–ธํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— global name ๊ณผ๋Š” ๋ฌด๊ด€ํ•จ
        return height;//global height๋ฅผ ๋ฐ˜ํ™˜
      }
      
      innerFn();//outerFn ๋‚ด๋ถ€ ์Šค์ฝ”ํ”„ InnerFn() ํ•จ์ˆ˜ ์‹คํ–‰ 
      
      console.log(age);//24
      console.log(name); //jimin
      
      return innerFn; //ํ•จ์ˆ˜ ์ž์ฒด๋ฅผ ๋ฐ˜ํ™˜
    }

	const innerFn = outerFn(); //๋‚ด๋ถ€ ์Šค์ฝ”ํ”„ outerFn() ํ•จ์ˆ˜ ํ• ๋‹นํ•˜์—ฌ ํ•จ์ˆ˜ ์ž์ฒด๋ฅผ ๋ฐ˜ํ™˜๊ฐ’์œผ๋กœ

	console.log(age); //์™ธ๋ถ€ ์Šค์ฝ”ํ”„์—์„œ global ๋ณ€์ˆ˜์ธ 27
	console.log(name); //์™ธ๋ถ€ ์Šค์ฝ”ํ”„์—์„œ global ๋ณ€์ˆ˜ ๊ฐ’์ด outerFn์ด ์‹คํ–‰๋˜๋ฉด์„œ ์žฌํ• ๋‹น๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— 'jimin'
	console.log(innerFn()); //outerFn() -> return innerFn -> return height ์ด๋ฏ€๋กœ global ๋ณ€์ˆ˜์ธ 179 

๐Ÿ“Œ Arrow Function ํ™”์‚ดํ‘œ ํ•จ์ˆ˜

  1. ์›๋ž˜์˜ ํ•จ์ˆ˜ ํ‘œํ˜„์‹
const add = function(x, y) { return x + y; }
console.log(add(5,8)); //13
  1. ํ™”์‚ดํ‘œ ํ•จ์ˆ˜ : function ๋Œ€์‹  ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๊ณ  => , return ์ƒ๋žต ๊ฐ€๋Šฅ,
const add = (x, y) => { return x + y };
console.log(add(10,20)); //30

const subtract = (x, y) => x - y; //return ์ƒ๋žต ๊ฐ€๋Šฅ
console.log(subtract(10,20));//-10

const multiply = (x, y) => (x * y); //ํ•„์š”์— ๋”ฐ๋ผ ์†Œ๊ด„ํ˜ธ
console.log(multiply(10,20));//200

const divideBy10 = x => x/10; //๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ํ•˜๋‚˜์ผ ๊ฒฝ์šฐ ์†Œ๊ด„ํ˜ธ ์ƒ๋žต ๊ฐ€๋Šฅ
console.log(divideBy10(100));//10
  1. ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•œ ํด๋กœ์ €
	const adder = x => {
      return y => {
        return x + y;
      }
    };
	console.log(adder(50)(10)); //60

	const subtractor = x => y => {//return ๋Œ€์‹  => 
      return x - y;
    }
    console.log(subtractor(50)(10)); //40

	const htmlMaker = tag => textContent => `<${tag}>${textContent}</${tag}>` 
    console.log(htmlMaker('div')('code states')); //<div>code states</div>
	
	const liMaker = htmlMaker('li'); //๋งค๊ฐœ๋ณ€์ˆ˜ tag ๊ฐ€ li๋กœ ์ „๋‹ฌ
	console.log(liMaker('1st item')); // <li>1st item</li>
	console.log(liMaker('2nd item')); // <li>2nd item</li>
      

๐Ÿ“Œ ์›์‹œ ์ž๋ฃŒํ˜• vs ์ฐธ์กฐ ์ž๋ฃŒํ˜•

  1. ์›์‹œ ์ž๋ฃŒํ˜•(string, number, boolean, undefined, null)์€ ๊ฐ’ ์ž์ฒด ๋ณ€๊ฒฝ์ด ๋ถˆ๊ฐ€ immutable, ๊ฐ’์€ stack์— ์ €์žฅ์ด ๋จ
	let name = 'codestates'; //stringํ˜•
	console.log(name); // 'codestates'
	console.log(name.toUpperCase()); //'CODESTATES'
	console.log(name); // 'codestates'

	name = name.toUpperCase();//์ƒˆ๋กœ์šด ๊ฐ’์œผ๋กœ ์žฌํ• ๋‹น
	console.log(name); //'CODESTATES' ์žฌํ• ๋‹นํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ’ ๋ณ€๊ฒฝ
  1. ์›์‹œ ์ž๋ฃŒํ˜•์„ ๋ณ€์ˆ˜์— ํ• ๋‹นํ•˜๊ฑฐ๋‚˜ ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ํ•จ์ˆ˜์˜ ์ „๋‹ฌ์ธ์ž๋กœ ์ „๋‹ฌํ•  ๊ฒฝ์šฐ, ๊ฐ’ ์ž์ฒด์˜ ๋ณต์‚ฌ๊ฐ€ ๋ฐœ์ƒ
	let oeverTwenty = true; //booleanํ˜•
	let allowedToDrink = overTwenty; // ๊ฐ’ ์ž์ฒด ๋ณต์‚ฌ๊ฐ€ ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— allowedToDrink ๋˜ํ•œ true
	overTwenty = false; // ์ƒˆ๋กœ์šด ๊ฐ’์œผ๋กœ ์žฌํ• ๋‹น
	console.log(overTwenty); //false
	console.log(allowedToDrink);//true ๋ณต์‚ฌํ•œ ๋ณ€์ˆ˜๋Š” ๋ณต์‚ฌํ•  ๋•Œ์˜ ๊ทธ ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ์œ ์ง€ 

	let variable = 'variable'; //string ํ˜•
	let variableCopy = 'variableCopy'; //string ํ˜•
	variableCopy = variable;// ๊ฐ’์„ ๋ณต์‚ฌํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— 'variable'
	variable = variableCopy; // ๋ณต์‚ฌํ•œ ๊ฐ’์„ ๋‹ค์‹œ ๋ณต์‚ฌํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— 'variable'
	console.log(variable === 'variable'); //true

	let currentYear = 2020;
	function afterTenYears(year){ year = year + 10; }
	aterTenYears(currentYear); //ํ•จ์ˆ˜์‹คํ–‰
	console.log(currentYear); //2020 ์œ—์ค„์˜ ํ•จ์ˆ˜์‹คํ–‰ํ•˜์˜€์ง€๋งŒ ๋ฐ˜ํ™˜ํ•˜์ง€๋„ ์•Š์•˜๊ณ  ๊ฐ’ ์ž์ฒด๋งŒ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ํฐ ์˜ํ–ฅ์„ ๋ผ์น˜์ง€ ์•Š์Œ
	
	function afterTenYear(currentYear){//๋งค๊ฐœ๋ณ€์ˆ˜ currentYear๊ณผ ์ „์—ญ ๋ณ€์ˆ˜ currentYear ๋Š” ๋ณ€์ˆ˜๋ช…์ด ๊ฐ™์ง€, ๋™์ผํ•œ ๋ณ€์ˆ˜๋Š” ์•„๋‹ˆ๋‹ค
      currentYear = currentYear + 10;
      return currentYear;
    }//๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ํ•จ์ˆ˜์˜ ์ง€์—ญ๋ณ€์ˆ˜๋กœ ๋งค ํ˜ธ์ถœ์‹œ ๋งˆ๋‹ค ์ƒˆ๋กญ๊ฒŒ ์„ ์–ธ๋จ

	let after10 = afterTenYear(currentYear);
	console.log(currentYear); //2020 ๊ฐ’์€ ๋™์ผ
	console.log(after10);// ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ 2020์„ ์ „๋‹ฌํ•˜์—ฌ 10์„ ๋”ํ•œ ๊ฐ’์„ ํ˜ธ์ถœํ•œ 2030
  1. ์ฐธ์กฐ ์ž๋ฃŒํ˜•์€ ์ฃผ์†Œ๊ฐ€ ์ €์žฅ์ด ๋˜๋ฉฐ stack์—๋Š” ์ฃผ์†Œ๊ฐ€ ์ €์žฅ์ด ๋˜์–ด ์žˆ๊ณ  heap์— ์ฃผ์†Œ๊ฐ€ ์ฐธ์กฐ๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ์ด ๋จ

  2. ์ฐธ์กฐ ์ž๋ฃŒํ˜•์˜ ๋ฐ์ดํ„ฐ๋Š” ๋™์  dynamic ์œผ๋กœ ๋ณ€ํ•จ

	const arr = [1,2,3];
	console.log(arr.length); //3
	arr.push(4,5,6);
	console.log(arr, arr.length); //[1,2,3,4,5,6] 6
	arr.pop();
	console.log(arr, arr.length); //[1,2,3,4,5] 5

	const obj = {};
	console.log(obj.length); //undefined;
	console.log(Object.keys(obj).length); // 0
	obj['name'] = 'codestates';
	obj.quality = 'best';
	obj.product = ['SW engineering', 'product manager', 'growth marketing', 'data science'];
	console.log(Object.keys(obj).length); //3
	delete obj.name;
	console.log(Object.keys(obj).length); //2
  1. ์ฐธ์กฐ ์ž๋ฃŒํ˜•์„ ๋ณ€์ˆ˜์— ํ• ๋‹นํ•  ๊ฒฝ์šฐ, ๋ฐ์ดํ„ฐ์˜ ์ฃผ์†Œ๊ฐ€ ์ €์žฅ๋˜์–ด ์˜ํ–ฅ์„ ๋ฏธ์นœ๋‹ค.
	const overTwenty = ['hongsik', 'minchul', 'hoyoung'];
	const allowedToDrink = overTwenty;//์ฃผ์†Œ ๋ณต์‚ฌ

	overTwenty.push('san'); 
	console.log(allowedToDrink); // ['hongsik', 'minchul', 'hoyoung', 'san']
	overTwenty[1] = 'chanyoung';
	console.log(allowedToDrink[1]); //'chanyoung'
	// ๊ฐ™์€ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•˜๋ฉด ์˜ํ–ฅ์„ ๋ฏธ์นœ๋‹ค. 

	const ages = [22,23,27];
	allowedToDrink = ages; //๋ฐฐ์—ด ์ฃผ์†Œ ๋ณต์‚ฌํ•˜์—ฌ ์žฌํ• ๋‹น
	console.log(allowedToDrink === ages); //true ๋ฐฐ์—ด ages ์™€ ๊ฐ™์€ ์ฃผ์†Œ ์ฐธ์กฐ
	consoel.log(allowedToDrink === [22,23,27]); //false ์š”์†Œ๋“ค์€ ๊ฐ™๊ฒ ์ง€๋งŒ ๋‹ค๋ฅธ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐ

	const num1 = [1,2,3];
	const num2 = [1,2,3];
	console.log(num1 === num2);// false ๊ฐ™์€ ์š”์†Œ๋“ค์ด์ง€๋งŒ ๋‹ค๋ฅธ ์ฃผ์†Œ ์ฐธ์กฐ

	const person = { son: { age: 9}, };
	const boy = person.son; // ๊ฐ์ฒด person์˜ ์†์„ฑ son ํ‚ค์˜ ๊ฐ’์ธ {age:9}๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ํ• ๋‹น
	console.log(boy); // boy = { age : 9}; 
	boy.age = 20; // boy = { age : 20 };
    console.log(person.son.age === boy.age); // true 20 ๊ฐ™์€ ์ฃผ์†Œ ์ฐธ์กฐ
	consoel.log(person.son === { age: 9 }); // ์ฃผ์†Œ๊ฐ€ ๋‹ค๋ฆ„
	console.log(person.son === { age : 20}); //๊ฐ’์€ ๊ฐ™์ง€๋งŒ ์ฃผ์†Œ๊ฐ€ ๋‹ค๋ฆ„

๐Ÿ“Œ Array ๋ฐฐ์—ด

  1. ๋ฐฐ์—ด์˜ ์œ ํ˜• ํŒ๋‹จ
	typeof arr = 'object' => 'array'๋กœ ํŒ๋ณ„ ๋˜์ง€ ์•Š์Œ
	Array.isArray(arr) = true => Array ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ true/false ๋กœ ํŒ๋‹จ
  1. ๋นˆ ๋ฐฐ์—ด ํ™•์ธ
	arr.length === 0 => ๊ธธ์ด๊ฐ€ 0์ž„์„ ์ด์šฉ
  1. ๋ฐฐ์—ด ์•ˆ์— ์ˆซ์ž, ๋ฌธ์ž, ํ•จ์ˆ˜, ๊ฐ์ฒด, ๋ฐฐ์—ด์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.
  2. pop push unshift shift ๋ฉ”์„œ๋“œ๋Š” ๊ธฐ์กด ๋ฐฐ์—ด์„ ๋ณ€๊ฒฝ์‹œํ‚จ๋‹ค.
  3. slice ๋ฉ”์„œ๋“œ๋Š” ๊ธฐ์กด ๋ฐฐ์—ด์„ ๋ณต์‚ฌํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
	const arr = ['peanut', 'butter', 'and', 'jelly'];
	
	
	arr.slice(1); // 1 ~ ๋ ['butter', 'and', 'jelly']
	arr.slice(0,1); // 0 ~ 0 ['peanut']
	arr.slice(0,2); // 0 ~ 1 ['peanut', 'butter']
	arr.slice(2,2); // 2 ~ 1 ์ด์ƒ๊ฐ์ง€ []
	arr.slice(2,20); // 2 ~ ๋ ['and', 'jelly']
	arr.slice(3,0); // 3 ~ -1 ์ด์ƒ [] => end === 0
	arr.slice(3,100); // 3 ~ ๋ ['jelly']
	arr.slice(5,1);//5 > arr.length []
	arr.slice(0); arr.slice(); //['peanut', 'butter', 'and', 'jelly']

๋‹ค๋งŒ, slice ๋ฉ”์„œ๋“œ๋Š” ์› ๋ฐฐ์—ด์˜ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ๋‹ค๋ฅธ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ ์›๋ฐฐ์—ด๊ณผ์˜ ๊ฐ™์€์ง€๋ฅผ ๋น„๊ตํ•  ๋•Œ๋Š” false๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

	arr.slice(0) === arr.slice(); //false ๋‘˜ ๋‹ค ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜์‹œํ‚ค๋Š”๋ฐ ๊ฐ™์€ ์ฃผ์†Œ๊ฐ€ ์•„๋‹˜ **

	let arr1 = [1,2,3];
    let arr2 = arr1.slice(); //arr2 = [1,2,3]
    console.log(arr1 === arr2); // false => ๊ฐ™์€ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ฏ€๋กœ false ๋ฐ˜ํ™˜
  1. call by reference ์ด๋ฏ€๋กœ ๋ณต์‚ฌ๋ฅผ ํ•  ๋•Œ ๋ฐฐ์—ด ์ „์ฒด๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ์ฃผ์†Œ๋„ ๊ฐ™์ด ์ฐธ์กฐํ•œ๋‹ค.
	const arr = ['zero', 'one', 'two', 'three', 'four', 'five'];
	
	function passedByReference(refArr) {
      refArr[1] = 'changed in function';
    }
    passedByReference(arr); 
	console.log(arr[1]);//'changed in function'; 
	consoel.log(arr); // ['zero', 'changed in function', 'two', 'three', 'four', 'five'];

	const assignedArr = arr; //๋ณต์‚ฌ = ๊ฐ™์€ ์ฃผ์†Œ ์ฐธ์กฐ
	assignedArr[5] = 'changed in assignedArr'; 
	console.log(arr[5]);//'changed in assignedArr';
	console.log(arr); //['zero', 'changed in function', 'two', 'three', 'four', 'changed in assignedArr'];
	

๐Ÿ“Œ Object ๊ฐ์ฒด

  1. ๊ฐ์ฒด์˜ ํƒ€์ž…๊ณผ ๊ธธ์ด
	let obj = {};
	typeof obj === 'object';
	obj.length === undefined; //๋ฐ˜๋ณต๋˜๋Š” ์†์„ฑ์„ ๊ฐ€์ง€์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ธธ์ด๋ฅผ ์•Œ์ˆ˜ ์—†์Œ.
	//๊ธธ์ด๋ฅผ ์•Œ๋ ค๋ฉด keys, values, entries ์†์„ฑ์„ ์ด์šฉํ•œ๋‹ค.
	Object.keys(obj).length;
	Object.values(obj).length;
	Object.entries(obj).length;
  1. ๊ฐ์ฒด์˜ ์†์„ฑ
    object.property = 'value'; , object['property'] = 'value'; ๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ’์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.
    delete object.property; delete object['property']; ๋ฅผ ์ด์šฉํ•˜์—ฌ ํ‚ค-๊ฐ’ ์Œ์„ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ๋‹ค.
    'property' in object ๋ฅผ ์ด์šฉํ•˜์—ฌ ์†์„ฑ ํ‚ค๊ฐ€ ํ•ด๋‹น ๊ฐ์ฒด์— ํฌํ•จ์—ฌ๋ถ€๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

  2. ์ „๋‹ฌ ์ธ์ˆ˜

 	const obj = { //์ฃผ์†Œ๋Š” ๊ฐ™์•„ = ์ฐธ์กฐ์ž๋ฃŒํ˜• 
      mastermind: 'Joker',
      henchwoman: 'Harley',
      relations: ['Anarky', 'Duela Dent', 'Lucy'],
      twins: {
        'Jared Leto': 'Suicide Squad',
        'Joaquin Phoenix': 'Joker',
        'Heath Ledger': 'The Dark Knight',
        'Jack Nicholson': 'Tim Burton Batman',
      },
    };
	function passedByReference(refObj) {
      refObj.henchwoman = 'Adam West';
    }
	passedByReference(obj); //์œ„์˜ ํ•จ์ˆ˜์— ์˜ํ•ด 'henchwoman'์˜ ์†์„ฑ์ด 'Adam West'๋กœ ๋ฐ”๋€œ
	console.log(obj.henchwoman); // 'Adam West'
	
	const assignedObj = obj;  //๋ณต์‚ฌ = ์ฃผ์†Œ ๊ฐ™์Œ = ์›๋ณธ ๊ฐ์ฒด๋„ ๊ฐ™์ด ๋ณ€๊ฒฝ๋จ
	assignedObj['relations'] = [1, 2, 3];
	console.log(obj['relations']); // [1,2,3]
	console.log(obj);
	/*
    const obj = { 
      mastermind: 'Joker',
      henchwoman: 'Adam West',
      relations: [1,2,3],
      twins: {
        'Jared Leto': 'Suicide Squad',
        'Joaquin Phoenix': 'Joker',
        'Heath Ledger': 'The Dark Knight',
        'Jack Nicholson': 'Tim Burton Batman',
      },
    };
    */

ํ•˜์ง€๋งŒ, Object.assign(,)๋ฅผ ์ด์šฉํ•œ ๋ณต์‚ฌ๋Š” ์ฃผ์†Œ๋งŒ ๋ณต์‚ฌํ•˜๊ณ  ๊ฐ’๋“ค์€ ๋ณต์‚ฌํ•˜์ง€ ์•Š์•„์„œ ๊ฐ’์ด ๋ณ€๊ฒฝ๋˜์–ด๋„ ์›๋ณธ ๊ฐ์ฒด์™€ ๊ฐ’์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค.

 	const copiedObj = Object.assign({}, obj); //๋นˆ ๋ฐฐ์—ด์— obj ๊ฐ์ฒด๋ฅผ ๋ณต์‚ฌํ•จ
	copiedObj.mastermind = 'James Wood';
	console.log(obj.mastermind);// 'Joker' ๋ณต์‚ฌํ•œ ๊ฐ์ฒด์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด๋„ ์› ๊ฐ์ฒด์˜ ๊ฐ’์€ ๋ณ€๊ฒฝ ๋˜์ง€ ์•Š๊ฒŒ ๋จ
	obj.henchwoman = 'Harley'; //์› ๊ฐ์ฒด์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด๋„ ๋ณต์‚ฌํ•œ ๊ฐ์ฒด์˜ ๊ฐ’์€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Œ
	//์ฆ‰, ๋ณต์‚ฌํ•œ ์‹œ์ ๋งŒ ๊ฐ™๊ณ , ๊ทธ ํ›„์˜ ๊ฐ๊ฐ์˜ ๊ฐ์ฒด์— ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด๋„ ์•„๋ฌด๋Ÿฐ ์ƒ๊ด€์ด ์—†๊ฒŒ ๋˜๋Š” ๊ด€๊ณ„
	
	delete obj.twins['Jared Leto'] ;//์› ๊ฐ์ฒด์˜ twins ๊ฐ์ฒด ์†์„ฑ์˜ 'Jared Leto' ์†์„ฑ์€ ์‚ญ์ œ๋จ 
	'Jared Leto' in copiedObj.twins; //false => ๊ทผ๋ฐ ์ด๊ฒƒ๋„ ์‚ญ์ œ๋จ ~~~~ ์–ด์ด์—†์–ด *** ๐Ÿšจ

๐Ÿ“Œ SpreadSyntax ...

  1. ์ „๊ฐœ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•  ๋•Œ ๋ณต์‚ฌํ•˜์—ฌ ์ „๋‹ฌํ•จ(๋นˆ๋ฐฐ์—ด, ์—ฌ๋Ÿฌ ๋ฐฐ์—ด, ์—ฌ๋Ÿฌ ๊ฐ์ฒด ๋ณ‘ํ•ฉ ๊ฐ€๋Šฅ)
	const spread = [1,2,3];
	const arr = [0, spread, 4]; // [0,1,2,3,4] ํŽผ์ณ์„œ

	const spread = [];
	const arr = [0, spread, 1]; // [0,1] ๋นˆ ๋ฐฐ์—ด์ผ ๊ฒฝ์šฐ ์•„๋ฌด๊ฒƒ๋„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์Œ

	const arr1 = [0,1,2], arr2 = [3,4,5];
	const concatenated = [..arr1,...arr2]; //[0,1,2,3,4,5]
	// const concatenated = [arr1,arr2];// ๋ฐฐ์—ด๋งŒ ๋„ฃ์œผ๋ฉด [[0,1,2],[3,4,5]]
	arr1.concat(arr2); // [0,1,2,3,4,5]
	
	const fullPre = {cohort: 7, duration: 4, mentor: 'hongsik', };
	const me = { time: '0156', status: 'sleepy', todos: ['coplit', 'koans'], };
	const merged = { ...fullPre, ...me }; //์†์„ฑ๋งŒ ์ „๋‹ฌ
	// const merge = {fullPre, me} => { {cohort: 7, duration: 4, mentor: 'hongsik', } , { time: '0156', status: 'sleepy', todos: ['coplit', 'koans'], } } 
	//merge ์— ํ• ๋‹น๋œ ๊ฒƒ์€ fullPre์™€ me์˜ reference ์ด๋‹ค. ์ด๋Š” shallow copy ์ธ๊ฐ€ deep copy???? **
	
	console.log(merged.fullPre === fullPre); //true
	console.log(merged.me === me); //true
  1. rest ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ํ•จ์ˆ˜์˜ ์ „๋‹ฌ์ธ์ž๋ฅผ ๋ฐฐ์—ด๋กœ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ์Œ.
	function returnFirstArg(firstArg){ return firstArg; }
	console.log(returnFirstArg('first', 'second', 'third')); // 'first' ํ•จ์ˆ˜ returnFirstArg ๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ํ•˜๋‚˜์ด๊ธฐ ๋•Œ๋ฌธ์— ์„ธ๊ฐœ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜์—ฌ๋„ ์ฒซ๋ฒˆ์งธ ์ธ์ž๋งŒ ์ „๋‹ฌ๋จ 
	
	function returnSecondArg(firstArg, secondArg){ return secondArg; }
	console.log(returnSecondArg('only give first arg')); //undefined ํ•จ์ˆ˜ returnSecondArg ๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๋‘๊ฐœ๊ฐ€ ํ•„์š”ํ•˜๊ณ  ๊ทธ ์ค‘ ๋‘๋ฒˆ์งธ ์ธ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ „๋‹ฌ์ธ์ž๋กœ ํ•˜๋‚˜๋งŒ ์ฃผ์–ด ๋‘๋ฒˆ์งธ ์ธ์ž๋Š” ์ „๋‹ฌ๋˜์ง€ ์•Š์•„ ์•Œ์ˆ˜ ์—†์Œ
	
	function getAllParamsByRestParameter(...args){ return args; }
	function getAllParamsByArgumentsObj(){ return arguments; }//arguments ๋Š” ๋ชจ๋“  ํ•จ์ˆ˜์˜ ์‹คํ–‰ ์‹œ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜๋Š” ๊ฐ์ฒด
	const restParms = getAllParamsByRestParameter('first', 'second', 'third');
	const argumentsObj = getAllParamsByArgumentsObj('first', 'second', 'third');

	consoel.log(restParms); //['first', 'second', 'third'] ์ „๋‹ฌ๋ฐ›์€ ์„ธ ๊ฐœ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋ฐฐ์—ด๋กœ ๋งŒ๋“ค์–ด ๋ฐ˜ํ™˜
	
	console.log(argumentsObj); //{ '0':'first', '1':'second', '2':'third' } ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐฐ์—ด์„ ๋ฐ›์•˜์„ ๋•Œ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒƒ์€ ๊ฐ์ฒด์ธ๋ฐ ํ‚ค๋Š” ์ธ๋ฑ์Šค๋กœ ์„ค์ •
	console.log(Object.keys(argumentsObj); //['0','1','2'] ๊ฐ์ฒด์˜ ํ‚ค๋งŒ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜
    console.log(Object.values(argumentsObj); //['first', 'second', 'third'] ๊ฐ์ฒด์˜ ๊ฐ’๋งŒ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜   
	console.log(Object.entries(argumentsObj)); // [['0', 'first'], ['1','second'], ['2', 'third']]
	
	console.log(restParms === argumentsObj);//false
	console.log(restParms === Object.values(argumentsObj));//false ๊ฐ™์€ ๋ฐฐ์—ด ์š”์†Œ๋ฅผ ๊ฐ€์ง€์ง€๋งŒ ๋‹ค๋ฅธ ์ฃผ์†Œ ์ฐธ์กฐ
	console.log(typeof restParms, Array.isArray(restParms));//'object' true ์ด๋Š” ๋ฐฐ์—ด
	console.log(typeof argumentsObj, Array.isArray(argumentsObj));//'object' false ์ด๋Š” ๊ฐ์ฒด
              
  1. rest ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์ „๋‹ฌ์ธ์ž์˜ ์ˆ˜๊ฐ€ ์ •ํ•ด์ ธ ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋„ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉ๊ฐ€๋Šฅ
	function sum(...nums){
      let sum = 0;
      for(let i = 0 ; i < nums.length ; i++){
        sum = sum + nums[i];
      }
      return sum;
    }
	console.log(sum(1,2,3));//6 ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ 1,2,3์€ ...nums ์— ์˜ํ•ด [1,2,3] ์œผ๋กœ ๋ณ€ํ™˜๋˜์–ด for ๋ฌธ ์ง„ํ–‰
  1. rest ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์ „๋‹ฌ์ธ์ž์˜ ์ผ๋ถ€์—๋งŒ ์ ์šฉ๊ฐ€๋Šฅ
	function getAllParms(required1, required2, ...args){
      return [required1, required2, arg];
    }
	console.log(getAllParms(123)); 
//[123, undefined, []) ์„ธ ๊ฐœ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ํ•„์š”ํ•˜์ง€๋งŒ 
//ํ•˜๋‚˜์˜ ์ „๋‹ฌ์ธ์ž๋งŒ ๋ฐ›์•˜์„ ๊ฒฝ์šฐ ์ฒซ๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์—ฐ๊ฒฐ์‹œํ‚ค๊ณ  
//๋ฐ›์ง€ ๋ชปํ•œ ๋‘๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ์— undefined, 
//์„ธ๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋ฐฐ์—ด๋กœ ๋ฐ›๋Š”๋ฐ ์ด ๋˜ํ•œ ์ „๋‹ฌ๋ฐ›์€ ์ธ์ž๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋นˆ๋ฐฐ์—ด[] ๋กœ ๋ฐ˜ํ™˜
	
	function makePizza(dough, name, ...toppings){
      const order = `You ordered ${name} pizza with ${dough} dough and ${toppings.length} extra toppings!`;
      return order;
    }
	console.log(makePizza('original')); 
	//	dough = original , name = undefined , ...toppgins = [] 
	// 'You ordered undefined pizza with original dough and 0 extra toppings!'
	console.log(makePizza('thin', 'pepperoni')); 
	//	dough = original , name = pepperoni , ...toppgins = [] 
	// 'You ordered pepperoni pizza with original dough and 0 extra toppings!'
	console.log(makePizza('napoli', 'meat', 'extra cheese', 'onion', 'bacon'));
	//	dough = napoli , name = meat , ...toppgins = [extra cheese, onion, bacon] 
	// 'You ordered meat pizza with napoli dough and 3 extra toppings!'

๐Ÿ“Œ Destructing Assignment ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น

  1. ๋ฐฐ์—ด ๋ถ„ํ•ด , rest/spread ๋ฌธ๋ฒ•์‚ฌ์šฉ์œผ๋กœ๋„ ๊ฐ€๋Šฅ(๋‹ค๋งŒ, ์ด๋Š” ์ˆœ์„œ๊ฐ€ ์ค‘์š”)
	const array = ['code', 'states', 'im', 'course'];
	const [first, second] = array; //['code', 'states']
	console.log(first, second); //'code states'
	
	const result = [];
	function foo([first, second]){
      	result.push(second);
      	result.push(first);
    }
	foo(array);// ํ•จ์ˆ˜ foo ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜ 2๊ฐœ๋Š” array ๋ฐฐ์—ด์˜ 0,1 ์ธ๋ฑ์Šค ์š”์†Œ๋งŒ ์ „๋‹ฌ๋จ
	console.log(result); //['state', 'code']์œ—์ค„์˜ ํ•จ์ˆ˜ ์‹คํ–‰์œผ๋กœ push๊ฐ€ ๋จ

const array = ['code', 'states', 'im', 'course'];
	const [start, ...rest] = array;//['code', ['states', 'im', 'course']
	console.log(start, rest); //'code ['state', 'im', 'course']

	const [first, ...middle, last] = array; //๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ค‘๊ฐ„์— rest ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.
  1. ๊ฐ์ฒด์˜ ๋‹จ์ถ• shorthand
	const name = '๊น€์ฝ”๋”ฉ';	
	const age = 28;
	const person = { name, age, level: 'Junior', };
	console.log(person);
	/* person = {
        	name : '๊น€์ฝ”๋”ฉ', age : 28, level: 'Junior' 
        }*/
  1. ๊ฐ์ฒด ๋ถ„ํ•ด , rest/spread ๋ฌธ๋ฒ•์‚ฌ์šฉ์œผ๋กœ๋„ ๊ฐ€๋Šฅ(๋‹ค๋งŒ, ์ด๋Š” ์ˆœ์„œ๊ฐ€ ์ค‘์š”)
	const student = { name: '๋ฐ•ํ•ด์ปค', major : '๋ฌผ๋ฆฌํ•™๊ณผ' };
 	const { name } = student; //๊ฐ์ฒด student ์˜ name ํ‚ค๋ฅผ ๋”ฐ๋กœ ์ €์žฅ ๊ฐ€๋Šฅ  = ๋ถ„ํ•ด
	console.log(name); //'๋ฐ•ํ•ด์ปค'

	const student = { name: '์ตœ์ดˆ๋ณด', major: '๋ฌผ๋ฆฌํ•™๊ณผ' };
	const {name, ...args} = student; 
	console.log(name); //'์ตœ์ดˆ๋ณด'
    console.log(args); //{major: '๋ฌผ๋ฆฌํ•™๊ณผ'}

	const student = { name: '์ตœ์ดˆ๋ณด', major: '๋ฌผ๋ฆฌํ•™๊ณผ', lesson: '์–‘์ž์—ญํ•™', grade: 'B+' };
  	function getSummary({name, lesson:course, grade}){
      return `${name}๋‹˜์€ ${grade}์˜ ์„ฑ์ ์œผ๋กœ ${course}์„ ์ˆ˜๊ฐ•ํ–ˆ์Šต๋‹ˆ๋‹ค`
    }
	console.log(getSummary(student)); 
	// '์ตœ์ดˆ๋ณด๋‹˜์€ B+ ์˜ ์„ฑ์ ์œผ๋กœ ์–‘์ž์—ญํ•™์„ ์ˆ˜๊ฐ•ํ–ˆ์Šต๋‹ˆ๋‹ค.'
	// ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ name, course, grade ๋กœ ํ•„์š”ํ•œ getSummary ํ•จ์ˆ˜์ธ๋ฐ, ๊ทธ ์ค‘ lesson ์€ student์˜ lesson๋กœ ์ ์šฉ๊ฐ€๋Šฅํ•˜๊ณ  student์˜ major ํ‚ค๋Š” ํ•„์š”ํ•˜์ง€ ์•Š์Œ

	const user = {
      name: '๊น€์ฝ”๋”ฉ',
      company: {
        name: 'Code States',
        department: 'Development',
        role: {
          name: 'Software Engineer'
        }
      },
      age: 35
    }

    const changedUser = { ...user,  name: '๋ฐ•ํ•ด์ปค', age: 20 }    //user ๊ฐ์ฒด๋ฅผ ๋ณต์‚ฌํ•˜๋˜, user์˜ name๊ณผ age์˜ ์†์„ฑ์„ ์žฌํ• ๋‹น
    console.log(chagedUser);
	/* changedUser = { 
    	name: '๋ฐ•ํ•ด์ปค', 
        company: {
        	name: 'Code States',
        	department: 'Development',
        	role: {
          	name: 'Software Engineer'
        	} 
      	},
        age : 20
       } */

    const overwriteChanges = { name: '๋ฐ•ํ•ด์ปค', age: 20,...user} 
    // name ๊ณผ age ์˜ ์†์„ฑ์„ ํ• ๋‹นํ•˜์ง€๋งŒ, user ๊ฐ์ฒด๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ user ์†์„ฑ์ค‘ name๊ณผ age์˜ ๊ฐ’์œผ๋กœ  ๋Œ€์ฒด๋˜์–ด ๊ฒฐ๊ตญ user์™€ ๊ฐ™์€ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐ
    console.log(overwriteChanges); 
	/* overwriteChanges = {
      	name: '๊น€์ฝ”๋”ฉ',
      	company: {
        	name: 'Code States',
        	department: 'Development',
        	role: {
          	name: 'Software Engineer'
        	}
      	},
      	age: 35
      } */
    //overwriteChanges === users => true

    const changedDepartment = {
      ...user, 
      company: {
        ...user.company, 
        department: 'Marketing'
      }
    }
    //user ๊ฐ์ฒด๋ฅผ ๋ณต์‚ฌํ•˜๋˜, user ์†์„ฑ ์ค‘ company ํ‚ค์˜ ๊ฐ’์— company ๊ฐ’์„ ์ถ”๊ฐ€ํ•˜๊ณ  department ๊ฐ’์€ ์žฌํ• ๋‹น
    console.log(changedDepartment);
	/* changedDepartment = { 
       	name: '๊น€์ฝ”๋”ฉ',
      	company: {
        	name: 'Code States',
        	department: 'Marketing',
        	role: {
          	name: 'Software Engineer'
        	}
      	},
      	age: 35
      } */               

0๊ฐœ์˜ ๋Œ“๊ธ€