HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

JavaScript Tutorial

JavaScript Introduction

What is JavaScriptJavaScript FeaturesJavaScript SyntaxHow to Add JavaScriptJavaScript OutputJavaScript Comments

JavaScript Basics

JavaScript VariablesJavaScript Data TypesJavaScript Operators

JavaScript Statement & Expression

JavaScript StatementsJavaScript ExpressionsJavaScript KeywordsJavaScript IdentifiersJavaScript Case SensitivityJavaScript SemicolonsJavaScript Code Blocks

JavaScript Conditions

JavaScript if StatementJavaScript if else StatementJavaScript else if StatementJavaScript switch Statement

JavaScript Loops

JavaScript for LoopJavaScript while LoopJavaScript do while LoopJavaScript break Statement
  1. Home
  2. /
  3. Tutorials
  4. /
  5. JavaScript Tutorial
  6. /
  7. JavaScript Expressions

JavaScript Statement & Expression

JavaScript Expressions

A JavaScript expression is a piece of code that produces a value.

Expressions can be simple or complex. They can include values, variables, operators, function calls, or a combination of these.

Example

Example

javascript

10 + 20

This is an expression because it produces the value 30.

Another example:

Example

javascript

let total = price * quantity;

Here, price * quantity is an expression because it calculates a value.

Expression Meaning

An expression always gives a result.

Example

javascript

let age = 25;

Here, 25 is an expression because it gives a value.

Example

javascript

let fullName = "Amit" + " " + "Kumar";

Here, "Amit" + " " + "Kumar" is an expression because it produces a single string value.

Expression and Statement Difference

A statement is an instruction.
An expression is code that produces a value.

Example

javascript

let result = 10 + 20;

In this code:

PartTypeMeaning
<code>10 + 20</code>ExpressionProduces the value 30
<code>let result = 10 + 20;</code>StatementStores the value in a variable

So, an expression can be part of a statement.

Numeric Expressions

Numeric expressions are expressions that produce number values.

Example

javascript

let a = 10;
let b = 5;

let sum = a + b;
let difference = a - b;
let product = a * b;

In this example:

ExpressionResult
<code>a + b</code>Adds two values
<code>a - b</code>Subtracts one value from another
<code>a * b</code>Multiplies two values

Numeric expressions are commonly used in calculations.

String Expressions

String expressions produce text values.

Example

javascript

let firstName = "Amit";
let lastName = "Kumar";

let fullName = firstName + " " + lastName;

Here, firstName + " " + lastName is a string expression.

The + operator joins the string values together.

Boolean Expressions

Boolean expressions produce either true or false.

Example

javascript

let age = 20;

let isAdult = age >= 18;

Here, age >= 18 is a boolean expression.

It checks whether the value of age is greater than or equal to 18.

More examples:

Example

javascript

10 > 5
20 === 20
5 < 3

These expressions return boolean values.

Assignment Expressions

An assignment expression assigns a value to a variable.

Example

javascript

let name = "Amit";

Here, "Amit" is assigned to the variable name.

Another example:

Example

javascript

let score = 10;
score = score + 5;

Here, score + 5 is calculated first, and then the result is assigned back to score.

Expressions with Variables

Expressions often use variables.

Example

javascript

let price = 500;
let quantity = 3;

let total = price * quantity;

Here, price * quantity is an expression that uses two variables.

If the value of price or quantity changes, the result of the expression also changes.

Expressions with Functions

A function call can also be an expression if it returns a value.

Example

javascript

function add(a, b) {
  return a + b;
}

let result = add(10, 20);

Here, add(10, 20) is an expression because it returns a value.

Expressions in Template Literals

Expressions can be used inside template literals with ${}.

Example

javascript

let name = "Amit";
let age = 25;

let message = `${name} is ${age} years old.`;

You can also use calculations inside ${}.

Example

javascript

let price = 100;
let quantity = 4;

let message = `Total price is ${price * quantity}`;

Here, price * quantity is an expression inside the template literal.

Complete Example

Complete Example

html

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript Expressions</title>
</head>
<body>

  <h1>JavaScript Expressions</h1>

  <p id="result"></p>

  <script>
    let price = 500;
    let quantity = 3;

    let total = price * quantity;
    let message = "Total Price: " + total;

    let isExpensive = total > 1000;

    document.getElementById("result").innerHTML =
      message + "<br>" +
      "Is expensive: " + isExpensive;
  </script>

</body>
</html>

Try It Yourself

Run the above example in the Try It Editor.

Try changing the values of price and quantity.

Also try creating your own numeric, string, and boolean expressions.

Important Points

  • An expression is code that produces a value.
  • Expressions can contain values, variables, operators, and function calls.
  • Numeric expressions produce numbers.
  • String expressions produce text.
  • Boolean expressions produce true or false.
  • Expressions are often used inside statements.
  • A function call can also be an expression if it returns a value.

Conclusion

JavaScript expressions are used to produce values.

They are used in calculations, string joining, comparisons, assignments, function calls, and template literals.

Understanding expressions is important because they are used in almost every JavaScript program.

PreviousJavaScript StatementsNextJavaScript Keywords