Increment & decrement operators
++
Increment operator; increments a value by 1
--
Decrement operator; decrements a value by 1
Pre increment
Syntax:
++variable
pre increment operator increments the
variable value by 1 immediately.
Post increment
Syntax:
variable++
post
increment operator increments the variable value by 1 after executing the
current statement.
Pre Decrement
Syntax:
--variable
pre decrement operator decrements the
variable value by 1 immediately.
Post Decrement
Syntax:
variable--
post decrement operator decrements the
variable value by 1 after executing the current statement.
arithmetic.html
<!DOCTYPE html> <html> <head> <title>Increment&Decrement Operators</title> <style> p{ font-size: 2em; color: seagreen; } </style> </head> <body> <p> <script type="text/javascript"> var a = 23; document.write("a = " + a + "<br />"); document.write("a++ = " + (a++) + "<br />"); document.write("++a = " + (++a) + "<br />"); document.write("a-- = " + (a--) + "<br />"); document.write("--a = " + (--a) + "<br />"); </script> </p> </body> </html>
No comments:
Post a Comment