Consider following code snippet:

var a = 2
var x  = 1 + (a*=2)
What will be the value of x variable after executing the code?
Explanation
Correct answer is 5
var a = 2;
var x  = 1 + (a=a*2);
console.log(x); //the result will be 5 because a*=2 is the same as a=a*2
and x = 1+4 = 5

@Vadim_Klimets Thanks! Improved)

2017 May 18, 12:31:49 AM

I think that it is better to explain like this. var a = 2; var x = 1 + (a=a*2); console.log(x); //the result will be 5 and a*=2 is the same as a=a*2

2017 Apr 30, 7:04:43 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes