DEV Community

Cover image for Incrementation in Javascript(forward & backward incrementation ++)
Emmanuel Onah
Emmanuel Onah

Posted on • Updated on

Incrementation in Javascript(forward & backward incrementation ++)

In this session, we will be discussing Algorithm, Forward & Backward incrementation.

First of all, what is an algorithm?
I could remember my first algorithm course in the university, my java lecturer asked the student to create a paper plane. Then she asked us how we emerged to making such similar planes?, then everyone started narrating in different ways. She then replied and said an algorithm mustn't be written in the same pattern but often results in the same result.

Algorithm:

An algorithm is a way or pattern you use in solving programmatic issues with consideration of time and space complexity.

So now haven explained algorithm, what is ++(incrementation)?

++ simply means incrementation by 1, it's similar to +1 but +1 is not effective and adviseable.

1. Forward incrementation

Forward incrementation is a simultaneous way of incrementing a value by 1. In this type of incrementation, the value immediately changes(with the addition of 1). But in the case of backward incrementation(counter++), the value gets incremented at the background but only gets it added when you use it a line after the line it was incremented.
For Example:

let prefixIncrementer = 0;
++prefixIncrementer;//1
Enter fullscreen mode Exit fullscreen mode

2. Backward incrementation

Backward incrementation is a way of incrementing a value that takes effect only when you invoke it a line after it was created.
For Example:

let backwardIncrementer = 0;
backwardIncrementer++;//0
backwardIncrementer;//1
Enter fullscreen mode Exit fullscreen mode

Alt Text

Top comments (0)