Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript statement reference manual

JavaScript statement reference manual


JavaScript Statements

In HTML, JavaScript statements are "commands" sent to the browser.

They tell the browser what to do.

The following JavaScript statement example tells the browser to output "Hello Dolly" into the HTML element with id="demo":

Example

document.getElementById("demo").innerHTML = "Hello Dolly.";

Try it »

For more tutorials about statements, please refer to our JavaScript Statements Tutorial.


JavaScript Statement Identifiers

JavaScript statements are usually identified by a statement identifier to indicate the JavaScript operation to be performed.

Statement identifiers are reserved keywords and cannot be used as variable names.

The following table lists all JavaScript statements:

Statement Description
break Exit a witch statement or loop
continue Skip the current iteration in a loop and continue to the next iteration of the loop.
debugger Stop executing JavaScript and call the debugging function.
do ... while Execute a block of statements, and continue executing that block while the condition is true.
for While the condition is true, a block of code can be executed a specified number of times.
for ... in Used to iterate over the properties of an array or object (loop over the properties of an array or object).
function Defining a function
if ... else ... else if Used to perform different actions based on different conditions.
return Exit a function and return its value.
switch Used to perform different actions based on different conditions.
throw Throw (generate) an error.
try ... catch ... finally Implement error handling, used together with catch.
var Declare a variable.
while When the condition is true, execute the block of statements.