Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between a++ and ++a in JavaScript?
++a returns the value of an after it has been incremented. It is a pre-increment operator since ++ comes before the operand.
a++ returns the value of a before incrementing. It is a post-increment operator since ++ comes after the operand.
Example
You can try to run the following code to learn the difference between i++ and ++i −
<html>
<body>
<script>
var a =10;
var b =20;
//pre-increment operator
a = ++a;
document.write("++a = "+a);
//post-increment operator
b = b++;
document.write("<br> b++ = "+b);
</script>
</body>
</html>Advertisements