Understanding Blocks


Blocks, also called statement blocks or compound statements, are sequences of statements that are treated as a single JavaScript statement. Blocks can be used any place that JavaScript expects a single statement.

To Create a Statement Block:

Enclose any number of JavaScript statements within curly braces.

For example:

 {     var test = "The answer is " + 42 ;     var test2 = " and ";     var test3 = 42 + " is the answer.";  } 

Note

Although the individual statements within a statement block should end with a semicolon, the statement block itself— even though it’s treated as a single statement—doesn’t terminate with its own semicolon. The curly brace ends the statement block.




Learn How to Program Using Any Web Browser
Learn How to Program Using Any Web Browser
ISBN: 1590591135
EAN: 2147483647
Year: 2006
Pages: 115
Authors: Harold Davis

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net