Conditional Statements in JavaScript

📰 Dev.to · Pranay Rebeyro

Learn to use conditional statements in JavaScript to control the flow of your code based on conditions, enabling your program to make decisions and execute different blocks of code accordingly.

beginner Published 11 Jul 2026
Action Steps
  1. Write an if statement to check a condition and execute a block of code if it's true.
  2. Use an if-else statement to run one block of code if the condition is true and another block if it's false.
  3. Apply an if-elif-else statement to check multiple conditions and execute different blocks of code based on each condition.
  4. Practice using conditional statements with different data types, such as numbers, strings, and booleans.
  5. Build a simple JavaScript program that uses conditional statements to make decisions based on user input.
Who Needs to Know This

This lesson is beneficial for frontend engineers, backend engineers, and full-stack developers who want to improve their JavaScript skills and write more efficient code. It's also useful for beginners who are just starting to learn programming concepts in JavaScript.

Key Insight

💡 Conditional statements are a fundamental concept in JavaScript that allow you to control the flow of your code based on conditions, making your program more dynamic and interactive.

Share This
🚀 Master conditional statements in JavaScript to take your coding skills to the next level! 🚀

Key Takeaways

Learn to use conditional statements in JavaScript to control the flow of your code based on conditions, enabling your program to make decisions and execute different blocks of code accordingly.

Full Article

Title: Conditional Statements in JavaScript

URL Source: https://dev.to/pranay_7424/javascript-conditional-statements-2f1a

Published Time: 2026-07-11T15:27:55Z

Markdown Content:
[Skip to content](https://dev.to/pranay_7424/javascript-conditional-statements-2f1a#main-content)

[![Image 1: DEV Community](https://media2.dev.to/dynamic/image/quality=100/https://dev-to-uploads.s3.amazonaws.com/uploads/logos/resized_logo_UQww2soKuUsjaOGNB38o.png)](https://dev.to/)

[Powered by Algolia](https://www.algolia.com/developers/?utm_source=devto&utm_medium=referral)

[Log in](https://dev.to/enter?signup_subforem=1)[Create account](https://dev.to/enter?signup_subforem=1&state=new-user)

## DEV Community

![Image 2](https://assets.dev.to/assets/heart-plus-active-9ea3b22f2bc311281db911d416166c5f430636e76b15cd5df6b3b841d830eefa.svg)0 Add reaction

![Image 3](https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg)0 Like ![Image 4](https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg)0 Unicorn ![Image 5](https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg)0 Exploding Head ![Image 6](https://assets.dev.to/assets/raised-hands-74b2099fd66a39f2d7eed9305ee0f4553df0eb7b4f11b01b6b1b499973048fe5.svg)0 Raised Hands ![Image 7](https://assets.dev.to/assets/fire-f60e7a582391810302117f987b22a8ef04a2fe0df7e3258a5f49332df1cec71e.svg)0 Fire

0 Jump to Comments 0 Save Boost

Copy link

Copied to Clipboard

[Share to X](https://twitter.com/intent/tweet?text=%22Conditional%20Statements%20in%20JavaScript%22%20by%20Pranay%20Rebeyro%20%23DEVCommunity%20https%3A%2F%2Fdev.to%2Fpranay_7424%2Fjavascript-conditional-statements-2f1a)[Share to LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fdev.to%2Fpranay_7424%2Fjavascript-conditional-statements-2f1a&title=Conditional%20Statements%20in%20JavaScript&summary=Conditional%20Statements%20Conditional%20statements%20allow%20JavaScript%20to%20execute%20different%20blocks%20of%20code...&source=DEV%20Community)[Share to Facebook](https://www.facebook.com/sharer.php?u=https%3A%2F%2Fdev.to%2Fpranay_7424%2Fjavascript-conditional-statements-2f1a)[Share to Mastodon](https://s2f.kytta.dev/?text=https%3A%2F%2Fdev.to%2Fpranay_7424%2Fjavascript-conditional-statements-2f1a)

[Share Post via...](https://dev.to/pranay_7424/javascript-conditional-statements-2f1a#)[Report Abuse](https://dev.to/report-abuse)

[![Image 8: Pranay Rebeyro](https://media2.dev.to/dynamic/image/width=50,height=50,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4016181%2F02986c0e-603b-47d5-a58a-158d8c9d0da6.png)](https://dev.to/pranay_7424)

[Pranay Rebeyro](https://dev.to/pranay_7424)
Posted on Jul 11

# Conditional Statements in JavaScript

[#javascript](https://dev.to/t/javascript)[#beginners](https://dev.to/t/beginners)[#programming](https://dev.to/t/programming)[#tutorial](https://dev.to/t/tutorial)

**Conditional Statements**

Conditional statements allow JavaScript to execute different blocks of code based on whether a condition is true or false.

**if statement**

if - The if statement executes a block of code only if the condition is true.

```
let age = 20;

if (age >= 18) {
console.log("Eligible to vote");
} //Output: Eligible to vote
```

**if else statement**

1. if...else - Use if...else when you want one block of code to run if the condition is true and another block if it's false.

```
let age = 16;

if (age >= 18) {
console.log("Eligible to vote");
} else {
console.log("Not eligible to vote");
} // Output: Not eligible to vote
```

**if elif statement**

1. if...else if...else - Use this when you have multiple conditions to check.

```
let marks = 85;

if (marks >= 90) {
console.log("Grade A");
} else if (marks >= 75) {
console.log("Grade B");
}
Read full article → ← Back to Reads