inblog logo
|
Coding_study
    바닐라 JS

    [바닐라 JS] Variables (변수)

    yuzu sim's avatar
    yuzu sim
    Oct 15, 2024
    [바닐라 JS] Variables (변수)
    Contents
    1. 일단 콘솔 값 출력해보자2. 변수의 가치에 대한 이해

     

    1. 일단 콘솔 값 출력해보자

    console.log(545454);
    notion image
    콘솔에 log 또는 print 하는 일을 함 → 괄호 안에 있는 것이 출력 됨
     
    String 출력할때 → 더블 쿼테이션 이나 싱글쿼테이션 둘 중 상관없음 다 쓸 수 있다.
    console.log("lalala");
    notion image
     

    2. 변수의 가치에 대한 이해

    2-1) 연산 콘솔 출력

    console.log(5 + 2); console.log(5 * 2); console.log(5 / 2);
    notion image
    자바스크립트는 파일을 위에서 아래로 읽는다.
     
    내가 값을 변경하고 싶을때 어떻게 해야 할까?
    notion image
     
    notion image
    내가 앞에 5를 6으로 바꾸고 싶을땐 이렇게 3번 바꾸고
     
    notion image
    다 바꾸고 싶을땐 6번이나 바꿔야한다.
     
    아.. 번거롭다.
     

    2-2) Variables 변수 사용

    Variables 변수라는 것을 사용할꺼야~
    값을 저장하거나 유지하는 역할을 함
     
    먼저 상수를(변하지 않는 값) 적음
    콘스트인 이 변수 이름을 적어야 함
    a = 5 같다고 정의
    const a = 5;
     
    이게 왜 중요할까? 5대신에 a를 쓸 수 있거든~~~
    결과는 같고
    const a = 5; console.log(a + 2); console.log(a * 2); console.log(a / 2);
    notion image
     
    옆에 숫자 2들도 변수로 정의 하면 나중에 값을 변경하고 싶을때 2번만 수정하면 된다.
    const a = 5; const b = 2; console.log(a + b); console.log(a * b); console.log(a / b);
     

    2-3) Variables의 이름을 어떻게 정하느냐?

    notion image
     
    Variables는 공백이 있을 수 없다. → 스페이스 사용 불가
    notion image
     
    자바스크립트 세상에서 단어에 공백이 필요하다면
    다음 단어의 첫 문자를 대문자료 표기한다.
     
    만약 아주 긴 변수의 이름을 가져야 한다면
    notion image
    즉, 카멜표기법을 사용함 (낙타 등 모양)
     
    파이썬에서는 언더스코어 사용하여 표기 → snake_case(뱀 모양)
    파이썬에서는 const없이 사용가능
    notion image
     

    2-4) 콘솔 확인

    const a = 5; const b = 2; const myName = "yuzu"; console.log(a + b); console.log(a * b); console.log(a / b); console.log("hello " + myName);
     
    notion image
     
    Share article

    Coding_study

    RSS·Powered by Inblog