DEV Community

Muhammad Jamshed
Muhammad Jamshed

Posted on

Bug or anything else Need Explanation for Js Increment

How the value of variable a=4? can anyone explain because we have incremented b=++a which is 4 but how a become 4?
Image description

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy 🎖️

It depends upon the position of ++ - if it is before the variable, it will increase the value in the variable and return the new value. If it is after, it will return return the value before the increment, but still increase the value stored in the variable.