+ 1

Why doesn't x=a++ increment a expected number?

/*Hello World! Why doesn't the piece of code below output 11 even though it's incremented in the x variable.*/ var a=10; var x; x=(a++); document.write(x);

29th Nov 2021, 1:08 PM
Ritunjoy Saikia
Ritunjoy Saikia - avatar
4 ответов
+ 4
Two types of increment operator: 1. Pre increment: ++var ( increments immediately ) 2. Post increment: var++ ( increment will be reflected after the current expression/statement/line ) If you don't know about these things, you need to complete your lesson first.
29th Nov 2021, 1:18 PM
Kashyap Kumar
Kashyap Kumar - avatar
+ 2
value of a will be increased after the statement x=a++; That is why it's called post increment
29th Nov 2021, 1:11 PM
Kashyap Kumar
Kashyap Kumar - avatar
+ 1
⚙️mega ☄️ could you broaden what is post increment Thanks
29th Nov 2021, 1:13 PM
Ritunjoy Saikia
Ritunjoy Saikia - avatar
+ 1
⚙️mega ☄️ The code snippet here was taken from a comment so I got curious as well as confused about it. Thanks btw Now I must go and complete my lesson
29th Nov 2021, 1:20 PM
Ritunjoy Saikia
Ritunjoy Saikia - avatar