NA +91-8727899942 thecoderjob@gmail.com

CHAPTER - 5

What is control flow in javascript.

In JavaScript, you can control the flow of your code using conditional statements like if-else and switch. These statements allow you to execute different blocks of code based on certain conditions.

Here's is the Code !!

//if-else
let num = 10;

if (num > 0) {
    console.log("Number is positive");
} else {
    console.log("Number is negative or zero");
}

//if-else if-else Statement
let num = 0;

if (num > 0) {
    console.log("Number is positive");
} else if (num < 0) {
    console.log("Number is negative");
} else {
    console.log("Number is zero");
}

//switch Statement
let fruit = "apple";

switch (fruit) {
    case "banana":
        console.log("It's a banana");
        break;
    case "apple":
        console.log("It's an apple");
        break;
    case "orange":
        console.log("It's an orange");
        break;
    default:
        console.log("Unknown fruit");
}

Chapter 4

Basic JavaScript Concepts

Previous chapter

Chapter 6

What is the loops in javascript

Next chapter

Get In Touch

NA

thecoderjob@gmail.com

+91-8727899942

Popular Links

© www.thecoderjob.com. All Rights Reserved.               Designed by HTML Codex