Javascript is a sequence of statements executed by the browser.
Javascript statements
The javascript statement is a command sent to the browser. These commands are used to tell the browser what to do.
This JavaScript statement tells the browser to output "Hello World" to the webpage ":
Document. Write ("Hello World ");
A semicolon is usually added at the end of each line of statements. Most people think this is a good programming habit, and this is often seen in Javascript cases on the web.
The semicolon is optional (based on JavaScript standards). The browser uses the end of the line as the end of the statement. For this reason, we often see examples with no semicolons at the end.
Note:You can use semicolons to write multiple statements in a row.
JavascriptCode
JavaScript code is a sequence of JavaScript statements.
The Browser executes each statement in order of writing.
In this example, a title and two paragraphs are output to the webpage:
<SCRIPT type = "text/JavaScript"> document. write ("
Tiy
JavaScript code block
Javascript can be combined in batches.
The code block starts with the left curly braces and ends with the right curly braces.
The function of a code block is to execute the statement sequence together.
In this example, a title and two paragraphs are output to the webpage:
<SCRIPT type = "text/JavaScript"> {document. write ("
Tiy
The previous example is of little use. It only demonstrates the use of code blocks. A code block is usually used to combine several statements in a function or Condition Statement (for example, if the condition is met, You can execute this statement to group it ).
You will learn more about functions and conditions in a later chapter.