Home
<!DOCTYPE html> <html> <body> <h1>Demo: JavaScript ++ and -- Operators</h1> <p>x = 5;</p> <p id="p1">x++=</p> <p id="p2">x=</p> <p id="p3">++x=</p> <p id="p4">x--=</p> <p id="p5">x=</p> <p id="p6">--x=</p> <script> let x = 5; document.getElementById("p1").innerHTML += x++; //post increment document.getElementById("p2").innerHTML += x; // value changes here document.getElementById("p3").innerHTML += ++x; //pre increment & value changes here document.getElementById("p4").innerHTML += x--; //post decrement document.getElementById("p5").innerHTML += x; //value changes here document.getElementById("p6").innerHTML += --x; //pre decrement and value changes here </script> </body> </html>
Result: