
+ 더하기
- 빼기
* 곱하기
/ 나누기
% 나머지값
** 지수 (거듭제곱)
++ 는 + 1, -- 는 - 1 을 의미
let a = 0;
a++; // a = a + 1; 콘솔에 찍으면 1 (0+1)
a--; // a = a - 1; 콘솔에 찍으면 0 (1-1)
++를 앞에 쓸때와 뒤에 때는 다르게 작용한다. (--도 마찬가지)
a++ 일 경우, 필요한 연산을 먼저 하고 그 뒤에 값이 증가
++a 일 경우, 값이 먼저 증가하고, 그 뒤에 필요한 연산을 함
즉, a = 0 일 때 a++ = 0, ++a = 1 이다
let a = 0;
console.log(a++); // 0 (먼저 a에 0이라는 값이 할당됨)
console.log(a); // 1 (그 뒤에 값이 +1 증가하였습니다)
let b = 0;
console.log(++b); // 1 (b의 값이 먼저 +1 증가하였습니다)
console.log(b); // 1
== 값이 같음
!= 값이 다름
=== 값과 타입이 둘다 같음
!== 값과 타입이 다름
console.log(1 == 1); //true
console.log(1 != 1); //false
console.log(1 != 2); //true
console.log(1 == '1'); //true
console.log(1 === 1); //true
console.log(1 === '1'); //false
console.log(true == 1); //true (값이 같음)
console.log(true === 1); //false (값은 같지만 타입이 다름)
const food1 = {
name: '피자',
}
const food2 = {
name: '피자',
}
console.log(food1 == food2); //false (메모리 주소가 다름)
console.log(food1 === food2); //false (메모리 주소가 다름)
console.log(food1.name == food2.name); //true
console.log(food1.name === food2.name); //true
Object들에는 메모리 주소가 할당되기 때문에 비교 대상은 객체의 key: value 가 아닌, 메모리 주소.
food1 = 0A111;
food2 = 0A112;
이런 식이기 때문에 food1와 food2는 값이 다름