JS 기본

SA Jung·2022년 10월 18일
0

JS & React JS

목록 보기
1/6
post-thumbnail

1. 변수선언

  • JS에서는 Python과 다르게 변수선언 방식에 차이점이 있다.
  • const

    • 변수의 재선언, 변수 재할당이 모두 불가능하다.
  • let

    • 변수의 재선언은 불가능하지만, 변수 재할당은 가능하다.
  • var

    • 예전의 방식으로 주로 쓰이지 않는다.
    • 변수의 재선언, 변수 재할당이 모두 가능하기 때문에 협업 프로젝트에서 쓰이지 않는다.

2. data type

  • null

    • '아무것도 없다.' = 변수에 값이 없다.
  • undefined

    • 변수는 선언 하였지만 아무것도 정의하지 않았다. = 말 그대로 "아무것도 없다!!"

3. list

  • list의 선언은 python과 동일하다.
  • push()

    • python의 append()와 동일

4. object(dict와 비슷한 접근)

const player = {
  name: "sa",
  age: "20",
  skill: "JS",
  study:true
}
console.log(player.name)
# sa
console.log(player.age)
# 20
console.log(player.skill)
# JS
console.log(player.study)
# true

5. 상태창 띄우기

  • prompt()

    • prompt창을 띄어서 값 받기
  • alert()

    • 경고창 띄우기

6. 연산자

  • && - AND연산자

  • || - OR연산자

7. 요소를 가지고 오는 방법

  • getElementById

    • document.getElementById()
  • querySelector

    • document.querySelector()

8. Events

  • classList

    • contains() : 클래스가 포함되어있는지 확인
    • remove() : 클래스 삭제
    • add() : 클래스 추가
    • toggle() : 위의 3가지를 한번에 처리해줌(클래스가 있으면 삭제, 클래스가 없으면 추가)

9. time

  • setInterval 호출방법

    • 5초 간격으로 함수 실행
      setInterval(sayHello, 5000);
  • setTimeout 호출방법

    • 5초 뒤에 함수 실행
      setTimeout(sayHello, 5000);

10. 자릿수 채우기

  • padStart

    • 자릿수가 될 때까지 앞쪽에 문자를 넣음 (단, String)
    • padStart(자릿수, 문자)
  • padEnd

    • 자릿수가 될 때까지 뒷쪽에 문자를 넣음 (단, String)
    • padEnd(자릿수, 문자)

11. JSON 변경

  • stringify

//data type을 무조건 String형태로 변환해줌.
JSON.stringify([1,2,3,4])
 => "[1,2,3,4]"
  • parse

//String형태를 JS data type으로 변환해줌.
JSON.parse("[1,2,3,4]")
  => [1,2,3,4]

12. localStorage

  • setItem(key,value)

    • 저장
  • getItem(key,value)

    • 가져오기
  • removeItem(key,value)

    • 삭제

13. forEach, filter

  • forEach()

    • arr.forEach(function) 를 통해 arr의 모든 요소들을 function할 수 있다.
  • filter()

    • arr.filter(item => item >= 4)을 통해 조건을 주어서 True를 만족하는 값들만 반환한다.
    • arr = [1,2,3,4,5,6,7]를 위와 같이 실행하면 [4,5,6,7]이 반환이 된다.
profile
Tomorrow will be better than yesterday :)

3개의 댓글

comment-user-thumbnail
2025년 6월 12일

I read that Post and got it fine and informative. Door pulls

답글 달기
comment-user-thumbnail
2025년 6월 17일

I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. 해외선물 솔루션

답글 달기

I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,.. 밤알바 Please continue this great work and I look forward to more of your awesome blog posts. 메랜대리 I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,.. 청주출장마사지 Great things you’ve always shared with us. Just keep writing this kind of posts.The time which was wasted in traveling for tuition now it can be used for studies.Thanks pol88 login I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,.. Take Profit Trader payout rules macau jitu

답글 달기