Statements and Expressions in Javascript

Working with Expressions & Statements in Javascript?

  • A statement controls the sequence of execution.
  • The Statement uses expression to evaluate a resulting outcome.
  • The Statement must end with a semicolon.
  • Whitespace such as tabs, spaces, and new lines is generally ignored in statements.
  • Blocks with statements begins with an opening brace ({) and ends with a closing brace (}) and is not ended with a semicolon.
  • In Javascript will anything that evaluates to a numeric value be an expression. Thus, the statement 4+9; returns the value 13, so it is an expression.
  • You can consider all expressions as statements in Javascript.
    For example:
    <script type="text/javascript">
      var a=4;
      var b="45", c=0, d=true;
      document.write("a: "+ a +" b: "+b);
      document.write(" c: "+ c +" d: "+d+"<br>");
      a = 3;
      b = 9;
      d = c = a+b;
      document.write("a: "+ a +" b: "+b);
      document.write(" c: "+ c +" d: "+d+"<br>");
    </script>
    The result should be:
    a: 4 b: 45 c: 0 d: true
    a: 3 b: 9 c: 12 d: 12
  • Go to the next session for more details about the handling of numbers and the create numeric expressions.

Prev. in menu javascript/Statements.php Next in menu
Prev. in menu javascript/Statements.php Next in menu
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.