javascript 문법 뽀개기

배운 내용

  • 많은 양을 직접 쓸 수가 없어서 노션 문서로 대체한다 :)
    문법 메모장

  • 그래도 기록하고 싶은 내용들
    1. 증감 연산자
    • count에 1을 먼저 더한 뒤, preIncrement 변수에 값을 할당
      let count = 1
      const preIncrement = ++count // 2
    • postIncrement 변수에 값을 먼저 할당한 뒤, count에 1을 먼저 더함.
      let count = 1
      const postIncrement = ++count // 1
    1. 클래스와 객체
    • 클래스 선언 기본형
      class Notebook {
        constructor(name, price, company) {
          this.name = name
          this.price = price
          this.company = company
        }
        // 메서드 선언
        printInfo() {
          console.log(`상품명: ${this.name}, 가격: ${this.price}`)
        }
      }
    • 객체 생성 및 메서드 사용
      const notebook1 = new Notebook('MacBook', 2000000, 'Apple')
      notebook1.printInfo() // 상품명: MacBook, 가격: 2000000원
    • 객체 리터럴 (클래스 선언을 활용하지 않고 바로 객체를 변수에 할당할 수 있음, 재사용성이 떨어짐)
      const computer = {
        name: 'Apple Macbook',
        price: 20000,
        printInfo: function () {
          console.log(`상품명: ${this.name}, 가격: ${this.price}`)
        }
      }
      computer.printInfo()
    1. 배열 반복문
    • for문을 활용한 반복문 속 배열 요소
      const rainbowColors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
       for (const color of rainbowColors) {
         console.log(color)
       }

좋은 웹페이지 즐겨찾기