Search⌘ K
AI Features

What's a Condition?

Explore how to implement conditions in JavaScript using if statements and boolean expressions. Understand comparison operators and learn coding best practices for readable and correct conditional logic.

We'll cover the following...

Suppose we want to write a program that asks the user to enter a number and then displays a message if the number is positive. Here is the corresponding algorithm.

Enter a number
		If the number is positive
    		Display a message

The message should display only if the number is positive; this means it’s “subject” to a condition.

The if statement

Here’s how you translate the program to JavaScript.

The console.log(...) ...