Skip to content

Commit 8aa8f4e

Browse files
committed
Changed the explanation for the pre (++i) and post (i++) increment operators.
1 parent 4dc2d9f commit 8aa8f4e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

content/javascript-101/operators.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ console.log(foo + ' ' + bar); // 'hello world'
1616
</javascript>
1717

1818
<javascript caption="Incrementing and decrementing">
19+
The pre-increment operator increments the operand before any further processing.
20+
// pre-increment
1921
var i = 1;
20-
var j = ++i; // pre-increment: j equals 2; i equals 2
21-
var k = i++; // post-increment: k equals 2; i equals 3
22+
console.log(++i); // => 2
23+
console.log(i); // => 2
24+
25+
The post-increment operator increments the operand after processing it.
26+
// post-increment
27+
var i = 1;
28+
console.log(i++); // => 1. This is because i was processed first
29+
console.log(i); // => 2. This is because the operand was incremented after processing in the previous step.
2230
</javascript>
2331

2432
## Operations on Numbers & Strings

0 commit comments

Comments
 (0)