Pre and Post Increment Operator in Javascript
Here are the implementation of Pre and Post Increment Operator in javascript language:
let num1 = 15, num2 = 20;
// Post Increment
let postNum = num1++;
// Pre Increment
let preNum = ++num2;
// Printing value of postNum after post Increment.
console.log("postNum = " + postNum);
console.log("num1 = " + num1);
// Printing value of preNum after pre Increment.
console.log("preNum = " + preNum);
console.log("num2 = " + num2);
Output
postNum = 15 num1 = 16 preNum = 21 num2 = 21
Pre Increment and Post Increment Operator in Programming
Pre Increment Operator and Post Increment Operator are the two ways of using the Increment operator to increment the value of a variable by 1. They can be used with numeric data values such as int, float, double, etc. Pre-increment and Post-increment perform similar tasks with minor distinctions. In this article, we will discuss the pre-increment and post-increment operators.
Table of Content
- What is a Pre-Increment Operator
- What is a Post-Increment Operator
- Pre and Post Increment Operator in C
- Pre and Post Increment Operator in C++
- Pre and Post Increment Operator in Java
- Pre and Post Increment Operator in Python
- Pre and Post Increment Operator in C#
- Pre and Post Increment Operator in Javascript
- Application of Pre and Post Increment