Skip to main content

JavaScript if Statement (Live Playground)

In this tutorial, we will explore the if statement, and learn how to use it in our code.

if Statement

The if statement is a conditional statement which used to make decisions in your code based on specific conditions.

The if statement is used to execute a block of code only if a specified condition is true.


const a = 10;

if (a > 5) {
console.log('a is greater than 5');

In the example above, the output is 'a is greater than 5' because the condition a > 5 is true.

Live Playground, Try it Yourself


Understanding and using if statement is crucial for controlling the flow of your JavaScript programs based on specific conditions.