Javascript Statements
JavaScript statements are commands that tell the browser what action to take. Statements are divided by a semicolon (;). A JavaScript statement generates a JavaScript code that is translated line by line through the browser line.
Statements Example
Edit it yourself<script>
let a, b, c; // Statement 1
a = 5; // Statement 2
b = 6; // Statement 3
c = a + b; // Statement 4
document.getElementById("Example").innerHTML = c;
</script>
- JavaScript statements often begin with a keyword to identify a JavaScript action.
- Here is a list of some of the keywords that you can learn further in this tutorial:
- In programming language, these programming instructions are called statements
Javascript Statements
Statements | Description |
---|---|
If else | The if statement is the basic control statement that allows JavaScript to make decisions and execute statements conditionally. |
switch case | This is a block in which the implementation of the code depends on the various cases. The interpreter examines each case against the value of the expression until the match is found. If nothing matches, the default condition is used |
While | The purpose of the loop is to repeatedly execute a statement or code block as long as the expression is correct. Once the expression is incorrect, the loop will exit. |
do while | A block of statements that is executed at least once and continues to be executed when the condition is true. |
for | At the same time, but the start, position and increase / decrease are done in the same line. |
for in | This loop is used to loop the properties of an object. |
continue | The current statement tells the interpreter to immediately start the next iteration of the loop and release the remaining code blocks. |
break | The brake statement is used to quickly exit the loop, which exits through a closed spiral bracket. |
function | A function is a group of reusable code that can be called anywhere in your program. The keyword function is used to declare a function. |
throw | Used to throw error. |
return | The return statement is used to return the value from the function. |
var | Used to declare a variable. |
let | Declare the block variable |
const | Declares a block constant |
Any expression is also a statement. Looks up expressions and operators for complete information about statements
The semicolon (;) character is used to separate statements in JavaScript code from the example above.
We will see the details of each statement in the next lecture