I am extremely new to JS and wanted to try the following.
var dev=4;
console.log(dev++);
I expected the output to be 5, but the output was 4. Can not understand the reason.
I am extremely new to JS and wanted to try the following.
var dev=4;
console.log(dev++);
I expected the output to be 5, but the output was 4. Can not understand the reason.
dev++ returns dev, then adds one to it
++dev adds one to it, then returns it (your goal)
x++
first uses the current value, then increments its value.
++x
first increments its value, then uses the value of the variable. This is the notation you're probably after.