Postfix Expressions in ECMAScript 2015
Expressions in ECMAScript – Part 3
ECMAScript 6
Foreword: In this part of the series, I talk about the Postfix Expressions in ECMAScript.
By: Chrysanthus Date Published: 13 May 2016
Introduction
Postfix Expression
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.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<script type="text/ECMAScript">
id1 = 10;
id2 = id1++;
alert(id2);
alert(id1);
</script>
</body>
</html>
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.
Chrys
Related Links
ECMAScript BasicsECMAScript Operators
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
ECMAScript Number
Scopes in ECMAScript
Mastering the ECMAScript (JavaScript) eval Function
Sending Email with ECMAScript
ECMAScript Insecurities and Prevention
Advanced Course
Advanced ECMAScript Regular Expressions
Promise in ECMAScript 2015
Generator in ECMAScript 2015
ECMAScript Module
More Related Links
Node Mailsend
EMySQL API
Node.js Web Development Course
Major in Website Design
Low Level Programming - Writing ECMAScript Module
ECMAScript Course
BACK