모던 자바스크립트 Deep Dive
-
10장 객체 리터럴 | 모던 자바스크립트 Deep Dive모던 자바스크립트 Deep Dive 2023. 11. 2. 19:36
객체란? 자바스크립트는 객체 기반의 프로그래밍 언어이며, 자바스크립트를 구성하는 거의 "모든 것"이 객체다. 원시 값을 제외한 나머지 값(함수, 배열, 정규 표현식 등)은 객체다. 원시 타입은 단 하나의 값만 나타내지만 객체 타입은 다양한 타입의 값(원시 값 또는 다른 객체)을 하나의 단위로 구성한 복잡한 자료구조다. 또한 원시 타입의 값, 즉 원시 값은 변경 불가능한 값(immutable value)이지만 객체 타입의 값, 즉 객체는 변경 가능한 값(mutable value)이다. var counter = { num: 0,// 프로퍼티 increase: function () { // 메서드 this.num++; } }; 객체는 0개이상의 프로퍼티로 구성된 집합이며, 프로퍼티는 키와 값으로 구성된다. 객..
-
09장 타입 변환과 단축 평가 | 모던 자바스크립트 Deep Dive모던 자바스크립트 Deep Dive 2023. 10. 31. 16:48
타입 변환이란? 자바스크립트의 모든 값은 타입이 있다. 값의 타입은 개발자의 의도에 따라 다른 타입으로 변환할 수 있다. 개발자가 의도적으로 값의 타입을 변환하는 것을 명시적 타입 변환 또는 타입 캐스팅이라 한다. var x = 10; // 명시적 타입 변환 // 숫자를 문자열로 타입 캐스팅한다. var str = x.toString(); console.log(typeof str, str); // string 10 // x 변수의 값이 변경된 것은 아니다. console.log(typeof x, x); // number 10 개발자의 의도와는 상관없이 표현식을 평가하는 도중에 자바스크립트 엔진에 의해 암묵적으로 타입이 자동으로 변환되기도 한다. 이를 암묵적 타입 변환 또는 타입 강제 변환이라 한다. va..
-
08장 제어문 | 모던 자바스크립트 Deep Dive모던 자바스크립트 Deep Dive 2023. 10. 29. 20:20
제어문 제어문은 조건에 따라 코드 블록을 실행(조건문)하거나 반복 실행(반복문)할 때 사용한다. 일반적으로 코드는 위에서 아래 방향으로 순차적으로 실행된다. 제어문을 사용하면 코드의 실행 흐름을 인위적으로 제어할 수 있다. 블록문 블록문은 0개 이상의 문을 중괄호로 묶은 것으로, 코드 블록 또는 블록이라고 부르기도 한다. 자바스크립트는 블록문을 하나의 실행 단위로 취급한다. 블록문은 단독으로 사용할 수도 있으나 일반적으로 제어문이나 함수를 정의할 때 사용하는 것이 일반적이다. 블록문은 언제나 문의 종료를 의미하는 자체 종결성을 갖기 때문에 블록문의 끝에는 세미콜론을 붙이지 않는다는 것에 주의한다. // 블록문 { var foo = 10; } // 제어문 var x = 1; if (x < 10) { x++..
-
07장 연산자 | 모던 자바스크립트 Deep Dive모던 자바스크립트 Deep Dive 2023. 10. 27. 16:30
산술 연산자 단항 산술 연산자 1개의 피연산자를 산술 연산하여 숫자 값을 만든다. 단항 산술 연산자 의미 부수 효과 ++ 증가 O -- 감소 O + 어떠한 효과도 없다. 음수를 양수로 반전하지도 않는다. X - 양수를 음수로, 음수를 양수로 반전한 값을 반환한다. X 증가/감소(++/--) 연산자는 피연산자의 값을 변경하는 부수 효과가 있다. 증가/감소 연산을 하면 피연산자의 값을 변경하는 암묵적 할당이 이뤄진다. var x = 1; // ++ 연산자는 피연산자의 값을 변경하는 암묵적 할당이 이뤄진다. x++; // x = x + 1; console.log(x); // 2 // -- 연산자는 피연산자의 값을 변경하는 암묵적 할당이 이뤄진다. x--; // x = x - 1; console.log(x); ..
-
06장 데이터 타입 | 모던 자바스크립트 Deep Dive모던 자바스크립트 Deep Dive 2023. 10. 25. 20:16
데이터 타입 데이터 타입은 값의 종류를 말한다. 자바스크립트의 모든 값은 데이터 타입을 갖는다. 자바스크립트(ES6)는 7개의 데이터 타입을 제공한다. 7개의 데이터 타입은 원시타입(primitive type)과 객체 타입(object/reference type)으로 분류할 수 있다. 구분 데이터 타입 설명 원시 타입 숫자(number)타입 숫자. 정수와 실수 구분 없이 하나의 숫자 타입만 존재 문자열(string)타입 문자열 불리언(boolean)타입 논리적 참(true)과 거짓(false) undefined 타입 var 키워드로 선언된 변수에 암묵적으로 할당되는 값 null 타입 값이 없다는 것을 의도적으로 명시할 때 사용하는 값 심벌(Symbol)타입 ES6에서 추가된 7번째 타입 객체 타입 객체,..
-
05장 표현식과 문 | 모던 자바스크립트 Deep Dive모던 자바스크립트 Deep Dive 2023. 10. 23. 23:00
값 값은 식(표현식)이 평가되어 생성된 결과를 말한다. 평가란 식을 해석해서 값을 생성하거나 참조하는 것을 의미한다. // 변수에는 10 + 20이 평가되어 생성된 숫자 값 30이 할당된다. var sum = 10 + 20; sum 변수에 할당 되는 것은 10 + 20이 평가된 결과인 값 30이다. 리터럴 리터럴은 사람이 이해할 수 있는 문자 또는 약속된 기호를 사용해 값을 생성하는 표기법을 말한다. // 숫자 리터럴 3 3 사람이 이해할 수 있는 아라비아 숫자를 사용해 숫자 리터럴 3을 코드에 기술하면 자바스크립트 엔진은 이를 평가해 숫자 값 3을 생성한다. 표현식 표현식은 값으로 평가될 수 있는 문이다. 즉, 표현식이 평가되면 새로운 값을 생성하거나 기존 값을 참조한다. var score = 100;..
-
04장 변수 | 모던 자바스크립트 Deep Dive모던 자바스크립트 Deep Dive 2023. 10. 23. 21:53
10 + 20 자바스크립트 엔진이 위 자바스크립트 코드를 계산(평가 evaluation) 하려면 먼저 10, 20 +라는 기호(리터럴 literal과 연산자 operator)의 의미를 알고 있어야 하며, 10 + 20이라는 식(표현식)의 의미도 해석(파싱)할 수 있어야 한다. 사람은 계산과 기억을 모두 두뇌에서 하지만, 컴퓨터는 연산과 기억을 수행하는 부품이 나눠져 있다. 컴퓨터는 CPU를 사용해 연산하고, 메모리를 사용해 데이터를 기억한다. 메모리는 데이터를 저장할 수 있는 메모리 셀의 집합체다. 메모리 셀 하나의 크기는 1바이트(8비트)이며, 컴퓨터는 메모리 셀의 크기, 즉 1바이트 단위로 데이터를 저장하거나 읽어들인다. 각 셀은 고유의 메모리 주소를 갖는다. 컴퓨터는 모든 데이터를 2진수 로 처리한..