⇧
vadnica-logo
Editor My Blog Password Manager Finance My Services About the Project Telegram O meni O meni

JavaScript Statements

JavaScript statements are the building blocks of every program. These are instructions that the browser or JavaScript engine executes one after another. A program is essentially a list of these statements, executed in sequence – from top to bottom, exactly in the order they are written.

Each statement usually ends with a semicolon (;), which separates commands and prevents errors in code interpretation. JavaScript is flexible regarding whitespace (spaces, tabs, newlines), allowing developers to format code for maximum readability and clarity. To organize multiple statements into a single logical unit, we use code blocks, marked with curly braces { ... }, which are essential for functions, loops, and conditional statements.

Understanding the correct syntax of statements, the use of semicolons, and code formatting is fundamental to writing clean, efficient, and error-free code.

EXAMPLE
RESULT
Concept Example Description
Execution Order
Sequential executionlet x = 5; let y = 10; Code executes from top to bottom, line by line.
Semicolon (;)
Statement terminatorlet a = 1; let b = 2; Semicolon marks the end of a statement. Allows multiple commands on one line.
Whitespace
Indentationif (true) {
  console.log("Hello!");
}
Spaces and tabs do not affect code execution but improve readability.
Line Breaks
Line breakslet longString = "This is a very long
  text line";
Long statements can be split into multiple lines for better readability.
Code Blocks { ... }
Code blocks{
  let x = 1;
  let y = 2;
}
Curly braces group multiple statements together (e.g., in functions, loops, if statements).
Control Flow Statements
if / elseif (x > 5) { ... } else { ... } Executes code if condition is true, otherwise executes alternative code.
switchswitch(day) { case 1: ... break; } Selects one of many code blocks to be executed based on a value.
Loops & Jumps
breakif (x === 5) break; Immediately terminates a loop or switch statement.
continueif (x % 2 === 0) continue; Skips the rest of the current iteration and moves to the next one.
returnreturn x + y; Ends a function and returns a value.
RESULT