Variables are used to store this information.
A variable is a 'named storage' for data.
변수는 데이터의 '이름이 지정된 저장소'이다.
let message;
→ 변수 선언
Now, we can put some data into it by using the assignment operator =
할당 오퍼레이터 '='를 사용해서 변수에 데이터를 넣는다.
let message;
message = 'Hello';
To be concise, we can combine the variable declaration and assignment into a single line
let message = 'Hello';
We can put any value in the box.
We can also change it as many times as we want.
let message;
message = 'Hello!';
message = 'World';
When the value is changed, the old data is removed from the variable.
We can also declare two variables and copy data from one into the other.
2개의 변수를 선언하고 하나의 데이터를 복사할 수 있다.
let hello = 'Hello world';
let message;
message = hello;
alert(hello); // Hello world
alert(message); // Hello world
There are two limitations on variable names in JavaScript:
오직 문자, 숫자, $와_의 심볼만 가능
첫 번째로 숫자가 올 수 없음.
To declare a constant(unchanging) variable, use const instead of let
바뀌지않는 변수 선언을 위해 let 대신 const를 쓴다.
Variables declared using const are called 'constants'. They cannot be reassigned. An attempt to do so would cause an error.
There is a widespread practice to use constants as aliases for difficult-to-remember values that are unknown prior to execution.
실행 전 기억하기 어려운 값의 별칭으로 constants를 사용하는 관행이 있다.
Such constants are named using capital letters and underscores.
이러한 constant는 대문자와 _를 사용하여 이름짓는다.
A variable name should have a clean, obvious meaning, describing the data that it stores.
Using different variables for different values can even help the engine optimize your code.