JS 상수 (const)

2021. 7. 15. 21:10
728x90
 

상수 선언 : const 이름 =  ;
  상수는 변하지 않는 값
  const 변수들은 값을 한번 저장하면 두번째 다른 값을 저장 불가능, 처음 넣은 값으로 고정

 

 

 

 

const num = 10;
<!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

 

 

 

const num = 10; 이후 num = 20; 선언
<!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

BELATED ARTICLES

more