산술 연산자
01 덧셈 ( + )
let result = 1 + 1; // 결과: 2
02 뺄셈 ( - )
let result = 3 - 1; // 결과: 2
03 곱셉 ( * )
let result = 3 * 5; // 결과: 15
04 나눗셈 ( / )
let result = 6 / 3; // 결과: 2
05 나머지 ( % )
let result = 5 % 2; // 결과: 1
할당 연산자
01 등호 연산자 ( = )
let coffee = "Latte";
02 복합 할당 연산자
// 자주 사용함
x += 5; // x = x + 5
x -= 5; // x = x - 5
// 자주 사용하지 않음
x *= 5; // x = x * 5
x /= 5; // x = x / 5
x %= 5; // x = x % 5
비교 연산자
true 혹은 false의 값을 반환한다
01 동등 비교 연산자 ( == )
데이터 타입이 달라도 같다고 판단하기 때문에 사용하지 않는 것이 좋다
console.log(1 == '1'); // 결과: true
02 부등 비교 연산자 ( != )
데이터 타입이 달라도 같다고 판단하기 때문에 사용하지 않는 것이 좋다
console.log(1 != '1'); // 결과: false
03 일치 연산자 ( === )
데이터 타입까지 일치해야 true를 반환하는 연산자
console.log(1 === 1); // 결과: true
console.log(1 === '1'); // 결과: false
04 불일치 연산자 ( !== )
데이터 타입까지 일치해야 false를 반환하는 연산자
console.log(1 !== '1'); // 결과: true
05 작다 연산자, 작거나 같다 연산자 ( <, <= )
console.log(2 < 3); // 결과: true
console.log(2 <= 3); // 결과: true
console.log(3 <= 3); // 결과: true
논리 연산자
01 논리곱 연산자 ( && )
모든 게 true임을 평가한다
&& 앞에 있는 값이 truthy하면 뒤로 넘어가고
&& 앞에 있는 값이 falsy하면 그 상태로 값을 반환하다
console.log(true && true); // 결과: true
console.log(true && false); // 결과: false
console.log(false && true); // 결과: false
console.log(false && false); // 결과: false
02 논리합 연산자 ( || )
|| 앞에 있는 값이 falsy 하면 || 뒤로 넘어가고,
|| 앞에 있는 값이 truthy 하면 그 상태로 값을 반환하다
console.log(true || true); // 결과: true
console.log(true || false); // 결과: true
console.log(false || true); // 결과: true
console.log(false || false); // 결과: false
03 논리부정 연산자 ( ! )
논리부정 연산자는 항상 Boolean 타입을 반환하다
console.log(!true); // 결과: false
04 삼항 연산자
조건 ? true일 때 반환하는 값 : false일 때 반환하는 값
let x = 10;
let result = x < 5 ? "작다" : "크다";
console.log(result); // 결과: 크다
Cf) 타입 연산자 ( typeof )
console.log(typeof "Hi"); // 결과: String
반응형
'Front-end > Javascript' 카테고리의 다른 글
[JS] 조건문(Conditional Statement) (0) | 2025.01.07 |
---|---|
[JS] 함수(Function) (1) | 2025.01.06 |
[JS] 데이터 타입(Data Type) (1) | 2025.01.06 |
[JS] 변수(Variable) (0) | 2025.01.06 |
[JS] 실행 컨텍스트(Execute context)에 대해 알아보자 (4) | 2025.01.03 |