![[바닐라 JS] Variables (변수)](https://image.inblog.dev?url=https%3A%2F%2Finblog.ai%2Fapi%2Fog%3Ftitle%3D%255B%25EB%25B0%2594%25EB%258B%2590%25EB%259D%25BC%2520JS%255D%2520Variables%2520%28%25EB%25B3%2580%25EC%2588%2598%29%26logoUrl%3Dhttps%253A%252F%252Finblog.ai%252Finblog_logo.png%26blogTitle%3DCoding_study&w=2048&q=75)
1. 일단 콘솔 값 출력해보자
console.log(545454);

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

2. 변수의 가치에 대한 이해
2-1) 연산 콘솔 출력
console.log(5 + 2); console.log(5 * 2); console.log(5 / 2);

자바스크립트는 파일을 위에서 아래로 읽는다.
내가 값을 변경하고 싶을때 어떻게 해야 할까?


내가 앞에 5를 6으로 바꾸고 싶을땐 이렇게 3번 바꾸고

다 바꾸고 싶을땐 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);

옆에 숫자 2들도 변수로 정의 하면 나중에 값을 변경하고 싶을때 2번만 수정하면 된다.
const a = 5; const b = 2; console.log(a + b); console.log(a * b); console.log(a / b);
2-3) Variables의 이름을 어떻게 정하느냐?

Variables는 공백이 있을 수 없다. → 스페이스 사용 불가

자바스크립트 세상에서 단어에 공백이 필요하다면
다음 단어의 첫 문자를 대문자료 표기한다.
만약 아주 긴 변수의 이름을 가져야 한다면

즉, 카멜표기법을 사용함 (낙타 등 모양)
파이썬에서는 언더스코어 사용하여 표기 → snake_case(뱀 모양)
파이썬에서는 const없이 사용가능

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);

Share article