Assignment operator : Assignment : Operators JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Operators » Assignment »

 

Assignment operator














The basic format of the assignment operator is:








x = 6;



The assignment operator can also be stacked to create simultaneous assignments.








x = y = z = 6;



Multiple assignment operators are evaluated from right to left.








y = (x = 34;



the value 3 is assigned to the variable x, which is then added to the value 4 and assigned to the variable y.

Once the expression is fully evaluated, y will contain the value 7.












<html>
<SCRIPT LANGUAGE="JavaScript">
<!--
    x = 1;
    y = 2;
    z = 3;

    document.write("<U>After single assignment</U><BR>");
    document.write("x=",x,"<BR>y=",y,"<BR>z=",z,"<BR>");

    document.write("<U>After multiple assignment</U><BR>");
    document.write("x=",x,"<BR>y=",y,"<BR>z=",z,"<BR>");

    x = (y = 17((z = 2));

    document.write("<U>After multiple assignment in one expression</U><BR>");

    document.write("x=",x,"<BR>y=",y,"<BR>z=",z,"<BR>");

// -->
</SCRIPT>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Operators
» Assignment