Increment a Number with JavaScript: Help!

Tell us what’s happening:

Your code so far

var myVar = 87;

// Only change code below this line
myVar = myVar + 1;
myVar + 1 = myVar++;

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Safari/604.1.38.

Link to the challenge:

It seems like you’re also not clear on what the assignment operator = does. It is not the same as an equals sign in math, even though it uses the same symbol.

So the line myVar + 1 = myVar++; results in a ReferenceError, because myVar + 1 isn’t something you can directly assign a new value to.

More

The closest thing JavaScript has to the equals sign in math is the strict equality operator ===. So, to check if myVar + 1 is equal to myVar++, you could do this:

console.log(myVar + 1 === myVar++);

However, this log false, because the ++ operator is applied after evaluating the current expression if used like that.

There is a way to apply it before evaluating the current expression, which is by putting it before the variable. So:

myVar + 1 === ++myVar;

Evaluates to true.