> For the complete documentation index, see [llms.txt](https://phg0644.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://phg0644.gitbook.io/javascript/undefined-2.md).

# 변수와 상수, 대입 연산자

값을 할당할 수 있는 상자인 변수와 변수에 값을 대입시켜주는 연산자

## 📕 변수(Variable) 와 상수(Constant)

* 변수는 변하는 값이고 상수는 변하지 않는 값 즉, 변수는 값을 할당하여 사용하는 박스의 역할을 수행하고, 상수는 값 자체(1, 2 등)를 의미함
* 변수 할당은 var키워드를 이용해서 선언하고 대입 연산자(=)를 이용해 값을 할당함 (var 변수명 = 대입할 값)

```markup
<h1>변수와 상수</h1>
<script>
    // a는 변수 123은 상수, 대입연산자 : =
    var a = 123; // 변수 a에 123을 대입
    document.write(a);
</script>
```

{% embed url="<https://codepen.io/hyeongkyupark/pen/MWpGmKw>" %}

* 변수 명명 규칙
  * 변수명에는 오직 문자와 숫자, 그리고 기호 `$`와 `_`만 들어갈 수 있음
  * 첫 글자는 숫자가 될 수 없
