JavaScript Increment operator weird expression [closed] Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of JavaScript Increment operator weird expression [closed] without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Why the output of the bellow expression is 2,1?

let a = 1
let b = 2

a = (b+=a -=b)-a

console.log(`${a,b}`)

Answer

let a = 1
let b = 2
a = (b+=a-=b)-a (*)

a-=b means a = a-b = 1-2 = -1
a = -1
Substitute into (*) => a = (b+=(-1))-a
b+=(-1) means b=b + (-1) = b - 1 = 1

Substitute into (*) => a = (1)-a = 1-(-1) = 2
a=2 b=1
We are here to answer your question about JavaScript Increment operator weird expression [closed] - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji