Postfix Expressions in ECMAScript 2015
Expressions in ECMAScript – Part 3
Foreword: In this part of the series, I talk about the Postfix Expressions in ECMAScript.
By: Chrysanthus Date Published: 13 May 2016
The syntaxes for postfix expressions are:
LeftHandSideExpression [no LineTerminator here] ++
LeftHandSideExpression [no LineTerminator here] - -
As you can see, it deals with the increment and decrement operators. Everything in a line above, including the operator is part of the expression. The word, postfix means that the LeftHandSideExpression is typed before the operator.
The Postfix Increment Operator
The ++ Increment Operator: With this operator, the operand is a number. When it is placed in front of the operand (prefix), it behaves in one way. When it is placed after the operand (postfix), it behaves in another way. Our interest here is the postfix (after) operation. Here, the word, increment means add 1.
When it is postfix, it returns the operand value before adding 1 to it. The returned value is the original value of the operand. The increased value is the new value of the operand, which is not returned. Read and try the following code.
id1 = 10;
id2 = id1++;
The extra HTML code is to produce a web page.
If you had tried the above code, you would have noticed that the value for id2 is 10 and the final value for id1 is 11, confirming that the incrementing took place after the value was returned. Always remember that when it is placed postfix, the value of the operand is returned before it is incremented.
The decrement operator is --. It decreases its number by 1. The explanation is similar to the above and remember that the - - is placed after the operand, making it postfix.
That is it for this part of the series. We stop here and continue in the next part.
Related LinksECMAScript Basics
Expressions in ECMAScript
Statements in ECMAScript
Custom Objects in ECMAScript
Functions in ECMAScript
ECMAScript Date Object
The ECMAScript String Object
ECMAScript String Regular Expressions
ECMAScript Template Literal
The ECMAScript Array
ECMAScript Sets and Maps
Scopes in ECMAScript
Sending Email with ECMAScript
ECMAScript Insecurities and Prevention
Advanced ECMAScript Regular Expressions
Promise in ECMAScript 2015
Generator in ECMAScript 2015
More Related Links
Node.js Web Development Course
Major in Website Design
Low Level Programming - Writing ECMAScript Module