[TIL] 내배캠4기 React 8일차

hare·2022년 11월 7일
0

내배캠-TIL

목록 보기
6/75

Today is...

  • 자바스크립트 문법 뽀각
  • 알고리즘 되새기기
  • 시간복잡도 완벽 이해

나는 자바스크립트가 좋아요오..
C에 비하면 너무 선녀에요..
아니라면 미안합니다(아직 걸음마단계임)

오늘 강의 들으며 복습해본 내용들

템플릿 리터럴

백틱: 문자열 안에 변수의 값을 집어 넣을 수 있게 함

템플릿 리터럴: 변수값을 문자열로 변환 $ { }

증감연산자(전위/후위)

전위연산: 산술연산자를 만난 시점, 그 라인부터 바로 적용

let a = 10;
console.log(--a); //9

후위연산

let a = 10;
console.log(a++); //10
console.log(a); //11

strict 일치연산자

===

객체

//실습 예제
class Product{
    constructor(color, size, price){
        this.color =color
        this.size = size
        this.price = price
    }
    printInfo(){
        console.log(`color:${this.color} size:${this.size} price:${this.price}`)
    }
}

const jacket = new Product('red','M',100000)
const skirt = new Product('pink','L',150000)
jacket.printInfo()
skirt.printInfo()

클래스 정의 이유 -> 재사용성!!


this

: 객체 속성에 접근하는 키워드

객체 리터럴

: 클래스 같은 템플릿 없이 빠르게 객체를 생성하는 방법

const notebook={
    name: 'Macbook',
    price: 2000000,
    printInfo: function(){
        console.log(`name: ${this.name} price: ${this.price}`)
    }
}

notebook.printInfo()

for of 문

for(변수 of 객체)

  • 간단하게 객체의 값을 하나씩 할당할 수 있음
const rainbowColors = ['red', 'orange','yellow','green','blue','indigo','violet']
rainbowColors.push('ultraviolet')
console.log(rainbowColors)
rainbowColors.pop() //배열의 마지막 요소 제거


// // for(let i = 0; i< rainbowColors.length; i++){
// //     console.log(rainbowColors[i])
// // }

for(const color of rainbowColors){
    console.log(color)
}

배열도 객체와 같음. 즉, 속성과 메소드를 갖고있음!

시간복잡도

for else 문 (파이썬)

for문이 끝날 때까지 break문을 만나지 않았다면 else문을 실행

#Max값 구하는 예제에서 살펴보자!
input = [3, 5, 6, 1, 2, 4]

def find_max_num(array):
    # 이 부분을 채워보세요!
    for num in array:
        for compare_num in array:
            if num < compare_num:
                break
        else:
            return num #6!!!!!!!!!!!!

result = find_max_num(input)
print(result)
profile
해뜰날

1개의 댓글

comment-user-thumbnail
2022년 11월 8일

자바스크립트 = 선녀
ㅎㅎㅎ재밌는 표현이네요

답글 달기