Js Statements in JavaScript
? JavaScript Statements
Statements are the instructions that tell the browser what to do. They are like sentences in the JavaScript language.
What is a Statement?
A complete unit of execution.
Ends with a semicolon (
;) — though it’s often optional.Can be simple or complex (like
if,for,while, function declarations).
Types of Statements
1. Expression Statements
Execute an expression.
let x = 5;x = x + 1;console.log(x);2. Conditional Statements
Control flow based on conditions.
if (x > 5) { console.log("x is greater than 5");} else { console.log("x is 5 or less");}3. Loop Statements
Repeat code multiple times.
for (let i = 0; i < 5; i++) { console.log(i);}4. Declaration Statements
Define variables or functions.
var name = "Alice";function greet() { console.log("Hello!");}5. Jump Statements
Change the flow abruptly.
break; // exit a loop or switchcontinue; // skip to next loop iterationreturn; // exit a function and return a valueExample: Multiple Statements
let sum = 0;for (let i = 1; i <= 5; i++) { sum += i; // expression statement}console.log(sum); // expression statementSummary
Statements perform actions.
They can be simple or compound (blocks).
JavaScript programs are made of sequences of statements.
If you want, I can explain the difference between statements and expressions!