a = 1;
b = "1";
if (a == b && a = 1) {
    console.log("a==b");
}

The Javascript code above will result in an error in the if statement in Google Chrome 26.0.1410.43:

Uncaught ReferenceError: Invalid left-hand side in assignment

I think this is because the variable a in the second part of the statement &&, a=1 cannot be assigned. However, when I try the code below, I'm totally confused!

a = 1;
b = "1";
if (a = 1 && a == b) {
    console.log("a==b");
}

Why is the one statement right but the other statement wrong?

Edit
Report