JavaScript Statements

Subject: JavaScript

In JavaScript, a statement is a complete instruction that tells the browser to perform a task. These tasks can include declaring variables, making decisions, looping through data, or calling functions.


What is a JavaScript Statement?

A JavaScript statement performs an action, such as:

  • Declaring a variable
  • Displaying output
  • Executing logic
  • Repeating tasks

Syntax Rule

  • Most statements end with a semicolon ;
  • JavaScript allows omitting semicolons, but using them is a good practice for clarity and avoiding bugs

Example 1: Simple Statements


Example 2: Function and Loop Statements


Common Types of JavaScript Statements

  • Declaration statements: let x = 10;
  • Conditional statements: if, else, switch
  • Looping statements: for, while, do...while
  • Expression statements: x + y;
  • Function statements: function greet() {}
  • Return statement: return x;

Statement vs Expression

ConceptDescriptionExample
StatementPerforms an actionif (x > 0) { ... }
ExpressionProduces a valuex + 5, "Hi" + name

Key Takeaways

  • JavaScript programs are built from statements that perform tasks.
  • Statements should end with semicolons to avoid ambiguity.
  • Statements define the structure and flow of your code.
  • Learn to differentiate between statements and expressions.
  • Use statements to implement logic, control structures, and functional behavior.
Next : JS Variables and Data Types