What Is a Statement?

This section provides a quick description of different types of statements and a tutorial example on how to write expression and other statements.

What is a statement? A statement is a basic execution unit in JavaScript. Several notes about JavaScript statements:

Here is a JavaScript tutorial example that shows you different types of statements:

<!-- Statements.html
   Copyright (c) 2013 by Dr. Herong Yang, herongyang.com
<script type="text/javascript">
   var x,y,z; // A "var" statement

   x=1, y=4, z=9; /* An expression statement 
      with 3 comma operators and 3 assignment operators.
      The result this expression is 9.*/ 

   x*x; y*y; z*z; // 3 statements in 1 line

   { // a statement block
      x *= x; 
      y *= y;
      z *= z;

   if (true) // A "if" statement 
      document.write("7 statements in total.");

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

Flow Control Statements

What Is a Statement?

 Conditional "if" Statements

 Conditional "if" Statement Examples

 "switch ... case" Statements

 "switch ... case" Statement Example

 "for" Loop Statements

 "for" Loop Statement Example

 "while" Loop Statements

 "while" Loop Statement Example

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications


 PDF Printing Version