W3Newbie
  • HTML Tutorial
  • CSS Tutorial
  • Web Dev
    • VS Code Tutorial
    • Command Line Tutorial
    • Git Tutorial
    • Github Tutorial
    • Sass Tutorial
  • Courses
  • Resources
  • Tutorials
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu

JavaScript Expressions & Statements

Home » JavaScript Tutorial » JavaScript Introduction » JavaScript Expressions & Statements

Every line of code you write in JavaScript is categorized as either a Statement (an action) or an Expression (a value). Understanding the difference is foundational to reading and writing predictable code.

The easiest way to think about the distinction is this: If a piece of code produces a single value, it’s an Expression. If it performs an action, it’s a Statement.

Statements (Performs an Action)

A Statement is a complete unit of execution that commands the computer to perform an action. Statements typically end with a semi-colon (;).

A statement’s main purpose is to perform an action or control the flow of the program; it does not necessarily produce a value that you can use elsewhere but typically will have places for expressions to be added to produce a value.

Key Characteristics of Statements:

  • Action-Oriented: Declaring a variable, controlling a loop, or defining a function.
  • Examples: const x = 5;, if (condition) { ... }, for (...) { ... }.

Expressions (Produces a Single Value)

An Expression is any piece of code that resolves to (or evaluates to) a single, concrete value.

If you can place the code on the right side of an assignment operator (=), it is an Expression, because the right side must produce a value for the left side to store.

Key Characteristics of Expressions:

  • Value-Oriented: A number, a string, a calculation, or a function call that returns a result.
  • Examples: 10 + 5, "Hello", age > 18, myFunction().

Expressions VS. Statements

FeatureExpression (Produces a Value)Statement (Performs an Action)
Primary GoalProduces a single value.Performs an action or command.
Example Code42const answer = 42;
Arithmetic10 * (3 + 7)// N/A (Arithmetic is an Expression)
Declaration/Control// N/A (Declaration is a Statement)if (isAdult) { ... }
Function UseMath.max(10, 20)function greet() { … }

The Overlap: Expression Statements

In JavaScript, most of the code you write will be an Expression Statement. An expression statement is a statement that consists of an expression followed by a semicolon. Essentially, any valid expression can be turned into a statement by adding a semicolon at the end. This allows the side effects of an expression, such as variable assignment or function execution, to be performed as part of the program’s flow.

// Expression Statement Examples:
const total = 5 + 5; // The expression '5 + 5' is assigned to 'total'.

console.log("Expression Statement"); // console.log is an Expression producing a value.
// The semi-colon at the end turns the whole line into a Statement.
JavaScript

Testing for Expressions VS. Statements in the Console

In the console you can check on whether or not a lin of JavaScript is an expression or statement by seeing if the console returns the expected value (an expression) or the undefined primitive data-type (statement).

// Checking Expressions VS. Statements in the console
let x = 22 // Statement
undefined // (statement confirmed)
x // Expression (since it evaluates to the value 22)
22 // (expression confirmed)
JavaScript

Remember: you use expressions (ingredients/values) within the structure of statements (the instructions/recipe steps) to make your program run.

< Previous
Next Lesson >

  • JavaScript Tutorial
  • JavaScript Introduction
    • JavaScript’s History
    • Getting Started with JavaScript
    • JavaScript’s Syntax & Structure
    • JavaScript Variables
    • JavaScript Data Types
    • JavaScript Escape Sequences
    • JavaScript Operators
    • JavaScript Type Coercion
    • JavaScript Expressions & Statements
  • JavaScript Built-in Objects & Methods
    • JavaScript Primitives & Methods
    • JavaScript String Properties & Methods
    • JavaScript Number Methods & Global Functions
    • JavaScript Math Object
    • JavaScript Date Object
  • JavaScript Control Flow and Collections
    • JavaScript Conditional Logic
    • JavaScript Try/Catch Synchronous Error Handling
    • JavaScript Arrays
    • JavaScript Array Methods
    • JavaScript Loops
    • JavaScript Objects
    • JavaScript Objects vs. JSON
    • JavaScript Primitive vs. Reference Values

The Newbie Template Bundle

The 12 Website Bundle Pack

Subscribe on YouTube

Web Development Courses

The HTML Email Mastery Course - Build Responsive HTML Email Templates.

Latest Tutorial Posts

  • The HTML Email Mastery Course - Build Responsive HTML Email Templates.w3newbie.com
    HTML Email Mastery Course CouponOctober 12, 2020 - 8:10 pm
  • Create A 5 Page Website With PHP Includes, HTML5, CSS3 & Bootstrap 4w3newbie.com
    Create A 5 Page Website With PHP Includes, HTML5, CSS3 & Bootstrap 4April 22, 2019 - 1:48 pm
© w3newbie.com, 2026. Terms of Use. Privacy Policy.
Scroll to top Scroll to top Scroll to top