[자바 스크립트] 일치 연산자, 상수

남한탐정김정은·2023년 1월 10일
0

자바스크립트

목록 보기
9/32
post-thumbnail

일치 연산자

=== 자료형과 값이 같은지 비교
!== 자료형과 값이 다른지 비교

console.log(`20 == "20" : ${20 == "20"}`);
console.log(`20 == "20" : ${20 === "20"}`);
console.log(`0 == "" : ${0 == ""}`);
console.log(`0 == "" : ${0 === ""}`);

실행결과

20 == "20" : true
20 === "20" : false
0 == "" : true
0 === "" : false

상수

변경하지 않을 대상에 상수를 적용함

const를 사용하여 상수를 지정함

const pi = 3.141592;
pi = "";
console.log(pi);

실행결과

pi = "";
^
TypeError: Assignment to constant variable.
at Object. (C:\Users\jamong\Documents\node\tset1.js:2:4)
 at Module._compile (node:internal/modules/cjs/loader:1218:14)
 at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
 at Module.load (node:internal/modules/cjs/loader:1081:32)
 at Module._load (node:internal/modules/cjs/loader:922:12)
 at Function.executeUserEntryPoint as runMain
 at node:internal/main/run_main_module:23:47

상수는 값을 변경할 수 없기 때문에 오류를 뿜는다.

profile
남한에 놀러온 김..

0개의 댓글