JavaScript Statements

What are JavaScript Statements?

JavaScript statements are commands that tells the browser what to do. They are the building blocks of JavaScript code and are executed in the order they are written. Statements often end with a semicolon (;), although it’s not always mandatory.

Tutorials dojo strip

Assigment Statement

An assignment statement assigns a value to a variable.

JavaScript

Function Call Statement

A function call statement invokes a function.

JavaScript

Conditional Statement

A conditional statement executes code based on a condition.

JavaScript

Loop Statement

A loop statement repeats a block of code as long as a specified condition is true.

JavaScript

JavaScript Code Blocks

A code block is a group of statements enclosed in curly braces {}. It is often used with control structures like if statements and loops to execute multiple statements.

JavaScript

JavaScript Statements Example Code

Explanation of Code:

  • Assignment Statement: Assigns the value 10 to the variable x.
  • Function Call Statement: Displays an alert box with the value of x.
  • Conditional Statement: Checks if x is greater than 5 and logs a message if true.
  • Loop Statement: Logs numbers 0 to 4 to the console.
  • Code Block: Declares variables y and sum, calculates the sum of x and y, and logs the result.
JavaScript

JavaScript Labs

Tutorials dojo strip