전체 글
-
JS 자세히 알아보기 (전개 연산자, 데이터 불변성, 복사)JavaScript/JavaScript 2021. 6. 6. 23:51
전개 연산자 (Spread) // 전개 연산자 (Spread) const fruits = ['Apple', 'Banana', 'Cherry'] // ['Apple', 'Banana', 'Cherry'] console.log(fruits) // Apple Banana Cherry console.log(...fruits) // const toObject = (a, b, c) => ({ a, b, c }) function toObject(a, b, c){ return { a: a, b: b, c: c } } // toObject(fruits[0], fruits[1], fruits[2]) = toObject(...fruits) // {a: "Apple", b: "Banana", c: "Cherry"} conso..
-
JS 자세히 알아보기 (객체 데이터)JavaScript/JavaScript 2021. 6. 6. 03:58
객체 데이터 const userAge = { // key: value name: 'Yoo', age: 27 } const userEmail = { name: 'Yoo', email: 'ITBlue@tistory.com' } // Object.assign() // 열거할 수 있는 하나 이상의 출처 객체로부터 대상 객체로 속성을 복사할 때 사용 // 정적 메소드 const target = Object.assign(userAge, userEmail) // {name: "Yoo", age: 27, email: 'ITBlue@tistory.com'} console.log(target) // {name: "Yoo", age: 27, email: 'ITBlue@tistory.com'} console.log(userA..
-
JS 자세히 알아보기 (데이터)JavaScript/JavaScript 2021. 6. 4. 20:15
문자 데이터 const str1 = '0123' // 문자 데이터의 길이를 출력 // 출력 결과: 4 console.log(str1.length) const str2 = 'Hello world!' // 문자 데이터에서 주어진 단어를 찾으면 일치하는 첫번째 인덱스를 반환 // 출력 결과: 6 console.log(str2.indexOf('world')) // 문자열의 시작 지점과 마지막 지점 직전까지 새로운 문자열을 반환 // 출력 결과: Hel console.log(str2.slice(0, 3)) // 문자열을 교체해준다 // 출력 결과: Hello IT Blue console.log(str2.replace('world', 'IT Blue')) const str3 = ' Hello world ' // 모..
-
JS 알아보기 (클래스)JavaScript/JavaScript 2021. 6. 4. 00:57
생성자 함수 (prototype) // 일반 함수와의 차이점을 위해 파스칼 케이스로 함수명 작성 function Student(name, grade) { this.name = name this.grade = grade } Student.prototype.getStudent = function () { return `${this.name}는 ${this.grade}입니다` } // new 라는 키워드로 생성된 함수를 생성자 함수라고 부름 // 객체 데이터가 생성됨 // yoo, kim, lee 라는 변수는 생성자 함수에 인스턴스라고 부름 const yoo = new Student('Yoo', '4학년') const kim = new Student('Kim', '3학년') const lee = new Stu..
-
JS 알아보기 (함수)JavaScript/JavaScript 2021. 6. 2. 22:13
함수 https://bluelearn.tistory.com/39?category=947483 화살표 함수 // 화살표 함수 // 일부 내용을 생략해서 축약형으로 작성이 가능하다 // () => {} vs function () {} // 함수 표현 const double = function (x) { return x * 2 } // double: 14 console.log('double: ', double(7)) const doubleArrow = (x) => { return x * 2 } const doubleArrow2 = (x) => x * 2 // doubleArrow: 14 console.log('doubleArrow', doubleArrow(7)) // doubleArrow2: 14 consol..
-
JS 알아보기 (변수 유효범위와 형 변환)JavaScript/JavaScript 2021. 6. 2. 14:16
변수 유효범위 // 변수 유효범위(Variable Scope) // var, let, const // let, const (블록 레벨에 유효 범위를 가짐) // var (함수 레벨에 유효 범위를 가짐) // 예시1 function scope() { if (true) { // let과 const는 블록 내부가 유효 범위 const a = 123 // 정상 작동 console.log(a) } // 오류 (유효 범위를 벗어남) console.log(a) } scope() // 예시2 function scope() { if (true) { // var는 함수 내부가 유효 범위 var a = 123 // 정상 작동 console.log(a) } // 정상 작동 console.log(a) } scope() 자료형 ..
-
JS 알아보기 (조건문과 반복문)JavaScript/JavaScript 2021. 6. 2. 13:27
If 조건문 // 조건문 (If statement) // If 조건문 if (조건) { // 조건이 참인 경우 실행 내용 } // If ~ Else 조건문 if (조건) { // 조건이 참인 경우 실행 내용 } else { // 조건이 거짓인 경우 실행 내용 } // If ~ Else IF ~ Else 조건문 if (조건1) { // 조건1이 참인 경우 실행 내용 } else if (조건2) { // 조건2가 참인 경우 실행 내용 } else { // 조건이 모두 거짓인 경우 실행 내용 } Switch 조건문 switch (변수) { case 값1: // 변수가 값1인 경우 실행 내용 break case 값2: // 변수가 값2인 경우 실행 내용 break case 값3: // 변수가 값3인 경우 실행 ..
-
JS 알아보기 (연산자)JavaScript/JavaScript 2021. 5. 28. 05:09
산술 연산자 (arithmetic operator) // 산술 연산자 (arithmetic operator) // 3 console.log(1 + 2) // -2 console.log(5 - 7) // 12 console.log(3 * 4) // 5 console.log(10 / 2) // 2 console.log(7 % 5) 할당 연산자 (assignment operator) // 할당 연산자 (assignment operator) let a = 2 // a = a + 1 a += 1 // a -= 1 // a *= 1 // a /= 1 // a %= 1 // 3 console.log(a) 비교 연산자 (comparison operator) // 비교 연산자 (comparison operator) co..