JavaScript

JS | 연산자

개발 공부 2022. 12. 28. 10:46

산술 연산자

+ 더하기

- 빼기

* 곱하기 

% 나누기

++ 1씩 증가 =

-- 1씩 감소

 

비교 연산자

>

<=

>=

== (값만 같으면 true)

!=

=== (값도 같고, 타입도 같아야 true, 두개짜리보다 이걸 사용하는걸 더 권장함)

!==

 

대입 연산자

=
+=

-=

*=

%=

/=

 

논리 연산자

!

&&

||

 

삼항 연산자

조건식 ? 실행문1 : 실행문2

 

자바랑 연산자가 다 같지만 ===, !== 이 부분만 다르다.

 

var num1 = "10";
var num2 = 10;

console.log(num1 == num2); //true (값만 비교)
console.log(num1 != num2); //false

console.log(num1 === num2);//false (값과 타입까지 비교)
console.log(num1 !== num2);//true

var a;
var b = null;

//변수값 동시에 출력 ,
console.log(a,b, a==b); //undefined null true(둘다 값이 없기때문에 true)
console.log(a,b, a!=b); //undefined null false
console.log(a,b, a===b); //undefined null false(값은 같지만 타입이 다르기에 false)
console.log(a,b, a!==b); //undefined null ture