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 Yourself »

For more tutorials about statements, please refer to ourJavaScript Statements Tutorial。


JavaScript Statement Identifiers

JavaScript statements are usually identified by a statement identifier to determine 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 Exits a switch statement or loop
continue Skips the current iteration in a loop and continues with the next iteration in the loop
debugger Stops execution of JavaScript and calls the debugging function
do ... while Executes a block of statements and continues executing the block as long as the condition is true.
for While the condition is true, the code block can be executed a specified number of times.
for ... in Used to iterate over the properties of an array or object (performs a loop operation over the properties of an array or object).
function Defines a function
if ... else ... else if Used to execute different actions based on different conditions.
return Exits a function and returns the value of the function
switch Used to execute different actions based on different conditions.
throw Throws (generates) an error.
try ... catch ... finally Implements error handling, used together with catch.
var Declares a variable.
while When the condition is true, executes the statement block.
Other Extensions