Basic JavaScript - Increment a Number with JavaScript

Tell us what’s happening:
Describe your issue in detail here.

I have figured out the correct answer. it is “myVar++”.
But now, I m really confused about that why the following code DO run. “myVar = ++myVar” and “myVar++” are totally different.
plz help me.

Your code so far

let myVar = 87;

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 Edg/105.0.1343.33

Challenge: Basic JavaScript - Increment a Number with JavaScript

Link to the challenge:

The updates ++tVar or tVar++ also with --
will determine whether the assignment is done before or after the update

If you write this (keyword let omitted):

// or

There is no difference because there isn’t any assignment. Instead

b= ++a

In that code, b is assigned after a is updated, we have:

a b
6 6
In this code however
a b
6 5

As you can see in both cases a will be 6

Last but not least you can increment without update:

b = a + 1

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.