Pre-Increment : Prefix operator : Operators JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Operators » Prefix operator »

 

Pre-Increment













The pre-increment operator is placed directly before the variable.

The operation begins by incrementing the variable by 1.

The new incremented value is returned by the operation to be used in another expression.

If the variable is a string, it is converted to a number.

For example, the following segment of code








var price = 5
var newPrice = (++price3;



the value of 9 dollars would be stored in the variable newPrice.












<html>
    <script language="JavaScript">
    <!--
    document.write("<h3>Before Pre-decrement</h3>");
    num = new String("8");
    document.write("num=",num,"<br>")
    returnValue = --num;
    document.write("<h3>After Pre-decrement</h3>");
    document.write("num=",num,"<br>");
    document.write("Value returned from operation is ",returnValue,"<br>");
    returnValue = num--;
    document.write("<h3>After Post-decrement</h3>");
    document.write("num=",num,"<br>");
    document.write("Value returned from operation is ",returnValue,"<br>");
    -->
    </script>
    </html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Operators
» Prefix operator