증감연산자

이서현·2022년 8월 8일
0

전위 연산자

let num = 1;
console.log(num++); // 1, 연산 되기 전 값이 나온다
console.log(num); // 2, 출력이 되고 연산을 하기 때문에 2인 것

위를 한 줄씩 작성해보자

console.log(num); // 1
num++; // num = 2
console.log(num); // 2

그래서 console.log(num++)의 출력값은 1

후위 연산자

let num = 1;
console.log(++num); // 2
console.log(num); // 2

전위 연산자는 출력이 되기 전 연산을 먼저 한다

++num;
console.log(num); // 2
console.log(num); // 2
profile
🌿💻💪🧠👍✨🎉

0개의 댓글