Assignment operator : Assignment « Operators « JavaScript Tutorial

JavaScript Tutorial
1. Language Basics
2. Operators
3. Statement
4. Development
5. Number Data Type
6. String
7. Function
8. Global
9. Math
10. Form
11. Array
12. Date
13. Dialogs
14. Document
15. Event
16. Location
17. Navigator
18. Screen
19. Window
20. History
21. HTML Tags
22. Style
23. DOM Node
24. Drag Drop
25. Object Oriented
26. Regular Expressions
27. XML
28. GUI Components
29. Animation
30. MS JScript
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript Tutorial » Operators » Assignment 
2. 4. 1. 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>
  
2. 4. Assignment
2. 4. 1. Assignment operator
2. 4. 2. x += 2 (Compound Plus)
2. 4. 3. x -= 2 (Compound Subtraction)
2. 4. 4. x *= 2 (Compound Multiply)
2. 4. 5. x /= 2 (Multiply Divide)
2. 4. 6. Advanced Assignment Operators
2. 4. 7. Assignment by Value Versus by Reference
w_ww___.___j__av___a__2___s__.___c___o__m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.