Statements

A statement contains an expression, and is, therefore, another type of syntactic container. Knowing how JavaScript sees expressions as distinct from statements is hugely helpful in avoiding the various traps and idiosyncrasies of the language.

A statement is formed in a variety of situations. These include the following:

  • When you terminate an expression with a semicolon (1 + 2;)
  • When you use any of the for, while, switch, do..while, or if constructs
  • When you create a function via a function declaration (function Something() {})
  • They are automatically formed by the language's natural automatic semicolon insertion (ASI)
The syntax of a function declaration (function name() {}) will always form a statement unless it appears in the context of an expression, in which case it'll naturally be a named function expression. For the nuanced differences between these, please revisit Chapter 6, Primitive and Built-In Types.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.84.112