
Before you learn ● 스코프(Scope) Closure (클로저) 란? MDN에서는 다음과 같이 클로저를 정의하고 있다. "A closure is the combination of a function and the lexical environment within which that function was declared" 클로저는 함수와 그 함수가 선언된 렉시컬 환경과의 조합이다. // outerFunc 함수 내부에서 중첩 함수 innerFunc가 정의되고 호출되었다. // 이때 중첩 함수 innerFunc의 상위 스코프는 외부 함수 outerFunc의 스코프이다. // 따라서 중첩 함수 innerFunc 내부에서 자신을 포함하고 있는 // 외부 함수 outerFunc의 x 변수에 접근할 수..

Scope (스코프) 란? Scope(스코프)를 직역하면 범위입니다. 예제로 Scope를 알아보겠습니다. // example 1 let fruit = 'apple'; if (fruit) { let msg = `my favorite fruit is ${fruit}!`; console.log(msg); // my favorite fruit is apple! }; console.log(msg); // ReferenceError: msg is not defined // 8번째 줄에서 찾는 변수 msg는 if문 안에 선언되어 있으므로 // 바깥쪽에서 안쪽의 변수 msg에게 접근할 수 없습니다. // example 2 let hello = 'Hello'; function helloMsg() { let userNam..

Before you learn ● Array ● Object ● Spread Syntax ● 원시자료형 & 참조자료형 얕은 복사 & 깊은 복사 배열 복사 // 배열 복사 방법 1 (slice()) let arr = [1, 2, 3, 4]; let copiedArr = arr.slice(); // slice는 원본배열을 변경하지 않습니다. (immutable) console.log(arr); // [1, 2, 3, 4] console.log(copiedArr); // [1, 2, 3, 4] console.log(arr === copiedArr); // false copiedArr.pop(); console.log(arr); // [1, 2, 3, 4] console.log(copiedArr); // [1,..

원시 자료형 (Primitive type data) 타입 종류 : Number, String, Boolean, undefined, null, symbol // primitive type data let num = 1; let copiedNum = num; console.log(num); // 1 console.log(copiedNum); // 5 console.log(num === copiedNum); // true copiedNum = 2; console.log(num); // 1 console.log(copiedNum); // 2 console.log(num === copiedNum); // false 원시 자료형을 변수에 할당하면 메모리 공간(변수)에 값 자체가 저장됩니다. 원시 값을 갖는 변수를 ..