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. |