JavaScript Statement
JavaScript statement is a command issued to the browser. The purpose of a statement is to tell the browser what to do.
JavaScript Statements
JavaScript statements are commands sent to the browser.
The purpose of these commands is to tell the browser what to do.
The following JavaScript statement outputs the text "Hello Dolly" to the HTML element with id="demo":
Example
document.getElementById("demo").innerHTML = "Hello Dolly.";
Semicolon;
Semicolon is used to separate JavaScript statements.
Usually we add a semicolon at the end of each executable statement.
Another use of semicolons is to write multiple statements in one line.
Writing:
a = 5; b = 6; c = a + b;
Is the same as writing:
a = 5; b = 6; c = a + b;
You may also see cases without semicolons.
In JavaScript, terminating statements with a semicolon is optional.
JavaScript Code
JavaScript code is a sequence of JavaScript statements.
The browser executes each statement in sequence in the order in which it was written.
This example outputs a title and two paragraphs to the web page:
Example
document.getElementById("demo").innerHTML="你好 Dolly"; document.getElementById("myDIV").innerHTML="你最近怎么样?";
JavaScript code blocks
JavaScript can be combined in batches.
A code block starts with a left curly brace and ends with a right curly brace.
The function of a code block is to execute a sequence of statements together.
This example outputs a title and two paragraphs to the web page:
Example
function myFunction() { document.getElementById("demo").innerHTML="你好Dolly"; document.getElementById("myDIV").innerHTML="你最近怎么样?"; }
You will learn more about functions in later chapters.
JavaScript Statement Identifier
JavaScript statements usually start with a Statement Identifier and execute the statement.
Statement identifiers are reserved keywords and cannot be used as variable names.
The following table lists JavaScript statement identifiers (keywords):