JS 상수 (const)
2021. 7. 15. 21:10
728x90
- 상수 선언 : const 이름 = 값 ;
상수는 변하지 않는 값
const 변수들은 값을 한번 저장하면 두번째 다른 값을 저장 불가능, 처음 넣은 값으로 고정

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>const</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script>
const num = 10;
document.write(num);
</script>
</head>
<body>
</body>
</html>
|
cs |

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>const</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script>
const num = 10;
num = 20; //값을 저장할 수 없음
document.write(num);
</script>
</head>
<body>
</body>
</html>
|
cs |
728x90
'JavaScript > Study' 카테고리의 다른 글
[JS] 증감 연산자 (++x, x++, --x, x--) (0) | 2021.07.15 |
---|---|
[JS] 대입 연산자 (=, +=, -=, *=, /=, %=) (0) | 2021.07.15 |
JS 산술 연산자 (+, -, *, /, %) (0) | 2021.07.15 |
JS 변수 (변수 선언, 변수 초기화, 식별자, var) (0) | 2021.07.15 |
[JS] 데이터 타입 (숫자, 문자열, 불리언) (0) | 2021.07.15 |