Close Menu
Developers GroundDevelopers Ground
  • Java
  • JavaScript
  • NodeJS

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot

JavaScript Control Statements

August 24, 2026

Datatypes in JavaScript

August 18, 2026

Get Started With Node.js: A Beginner’s Guide to Your First Application

August 13, 2026
Facebook Instagram
Developers GroundDevelopers Ground
  • Java
  • JavaScript
  • NodeJS
Facebook Instagram
Developers GroundDevelopers Ground
Home»JavaScript»JavaScript Control Statements
JavaScript

JavaScript Control Statements

Akshay KulkarniBy Akshay KulkarniAugust 24, 20263 Mins Read1 Views
Facebook Twitter LinkedIn WhatsApp Email
Share
Facebook Twitter LinkedIn Email WhatsApp

What are Control Statements?

  1. Normally JavaScript executes the program from top to bottom. Control statements allow you to change this normal flow.
  2. Control Statements are classified into three types
    1. Decision Making Statements
    2. Looping Statements
    3. Jump Statements

Decision Making Statements

  1. This category of conditional statements allow your program to make decisions.
  2. E.g. If user logged in show dashboard else show login page.

  3. Following are the decision making statements
    1. If…else 
    2. Switch
    3. Ternary

If statement

  1. This is the simplest conditional statement.
  2. Syntax
  3. if (condition) {

    // code

    }
  4. If the condition gets false then block doesn’t executes.
  5. A condition normally produces a Boolean value.
  6. let age = 15;

    if (age >= 18) {
    console.log("You are eligible to vote");
    }

If…else statement

  1. When there are two possible paths then you can use If along with else statement.
  2. if (condition) {

    // true

    } else {

    // false

    }
  3. let age = 16;

    if (age >= 18) {
    console.log("Adult");
    } else {
    console.log("Minor");
    }

 

If…else if…else

  1. You can use this when there are multiple conditions.
  2. JavaScript checks conditions from top to bottom as soon as one condition is true then if block executes and remaining else if conditions skipped.
  3. let marks = 85;

    if (marks >= 90) {
    console.log("Grade A+");
    } else if (marks >= 75) {
    console.log("Grade A");
    } else if (marks >= 60) {
    console.log("Grade B");
    } else if (marks >= 40) {
    console.log("Grade C");
    } else {
    console.log("Fail");
    }

 

Multiple Conditions

  1. JavaScript provides logical operators so that we can apply multiple conditions.
  2. AND – && : Both conditions must be true.
  3. let age = 25;
    let hasLicense = true;

    if (age >= 18 && hasLicense) {
    console.log("Allowed to drive");
    }
  4. OR -|| : At lease one condition must be true.
  5. let isAdmin = false;
    let isManager = true;

    if (isAdmin || isManager) {
    console.log("Access granted");
    }
  6. NOT – ! : Reverses a boolean value
  7. let isLoggedIn = false;

    if (!isLoggedIn) {
    console.log("Please login");
    }

 

Switch Statement

  1. Switch statement is useful when you want to compare one value against multiple possible values.
  2. switch (expression) {

    case value1:
    // code
    break;

    case value2:
    // code
    break;

    default:
    // code
    }
  3. let day = 2;

    switch (day) {

    case 1:
    console.log("Monday");
    break;

    case 2:
    console.log("Tuesday");
    break;

    case 3:
    console.log("Wednesday");
    break;

    default:
    console.log("Invalid day");
    }
  4. O/P: Tuesday

 

Ternary Operator

  1. It is a short form of if…else statement.
  2. Syntax: condition ? valueIfTrue : valueIfFalse
  3. let isLoggedIn = true;

    let message = isLoggedIn
    ? "Welcome"
    : "Please login";

 

Share. Facebook Twitter LinkedIn WhatsApp Email
Akshay Kulkarni

Related Posts

JavaScript August 18, 2026

Datatypes in JavaScript

JavaScript August 13, 2026

JavaScript Variables Explained: let, const and var for Beginners

JavaScript August 13, 2026

JavaScript for Beginners: What Is JavaScript and How Does It Work?

Leave A Reply Cancel Reply

More Post's
JavaScript August 24, 20261 Views

JavaScript Control Statements

1 Views

What are Control Statements? Normally JavaScript executes the program from top to bottom. Control statements…

Datatypes in JavaScript

August 18, 2026

Get Started With Node.js: A Beginner’s Guide to Your First Application

August 13, 2026

Node.js for Beginners: What Is Node.js and How Does It Work?

August 13, 2026
Facebook Instagram
  • Our Authors
  • Get In Touch
  • Privacy Policy
© 2026 Developers Ground

Type above and press Enter to search. Press Esc to cancel.