본문 바로가기

Programming/JavaScript

Values and Variables

let js = "amazing";
console.log(40 + 8 + 23 - 10);

console.log("Jonas");
console.log(23);

let firstName = "Jonas";
console.log(firstName);

console.log에 string으로 바로 Jonas를 넣든

상수에 Jonas를 저장하고

console에 log를 찍든 결과는 동일함

 

variable을 쓰는 이유?

firstName을 여러 군데서 쓴다고 가정

매번 각기 다른데의 값을 수정해줄 필요가 없다

why? firstName에 저장된 value만 수정해주면 되니까!

 

자바스크립트에서도 변수명 정할 때 camel case로 씀

e.g. firstName

 

변수명으로 정할 때 못 쓰이는 것들

reserved keywords

e.g. new, function

 

변수명 정할 때는 해당 변수가 어떤 value를 holding하고 있는지 쉽게 이해할 수 있게 정하는게 좋음!

// good example
let myFavoriteFood = 'Kimchi stew';
let myFavoriteDrink = 'Coffee';

// bad example
let food1 = 'Kimchi stew';
let food2 = 'Coffee';

'Programming > JavaScript' 카테고리의 다른 글

let, const and var  (0) 2022.07.10
Data Types (feat. 7 primitive data types)  (0) 2022.07.10
Linking a JavaScript File  (0) 2022.07.08
Hello World!  (0) 2022.07.07
Key Down Event  (0) 2022.03.11