In JavaScript, a statement is a unit of code that performs a specific action. It is used to create a program or to perform a specific task. There are different types of statements in JavaScript, such as control statements, loop statements, conditional statements, etc. Here are some examples of statements in JavaScript:
Control statements:
let age = 25;
if(age > 18) {
console.log('You are an adult');
} else {
console.log('You are not an adult');
}
Loop statements:
let i = 1;
while(i <= 5) {
console.log(i);
i++;
}
Conditional statements:
let a = 5; let b = 10; let result = (a > b) ? 'a is greater than b' : 'a is less than or equal to b'; console.log(result);
Expression statements:
let x = 10;
let y = 20;
let z = x + y;
console.log(z);
Jump statements:
for(let i = 1; i <= 10; i++) { if(i === 5) { continue; } console.log(i); }
In the above examples, we can see different types of statements that perform different actions such as conditional, looping, etc.