0% found this document useful (0 votes)
1 views

Javascript if Else Explained

The document explains JavaScript conditional statements, starting with the simple 'if' statement that executes code when a condition is true. It then describes the 'if...else' statement for choosing between two code blocks based on a condition, followed by the 'if...else if...else' statement for testing multiple conditions in sequence. Examples are provided for each type of statement to illustrate their usage.

Uploaded by

samuel asefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Javascript if Else Explained

The document explains JavaScript conditional statements, starting with the simple 'if' statement that executes code when a condition is true. It then describes the 'if...else' statement for choosing between two code blocks based on a condition, followed by the 'if...else if...else' statement for testing multiple conditions in sequence. Examples are provided for each type of statement to illustrate their usage.

Uploaded by

samuel asefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

JavaScript if...

else Statements Explained

1) The if Statement

The simplest form of conditional statement. It executes a block of code only if a condition is true.

Example:

let score = 85;

if (score >= 50) {

console.log("You passed the exam!");

2) The if...else Statement

Executes one block of code if the condition is true and another block if it is false.

Example:

let temperature = 15;

if (temperature > 20) {

console.log("It's warm outside.");

} else {

console.log("It's cold outside.");

3) The if...else if...else Statement

Tests multiple conditions in sequence.

Example:

let grade = 70;

if (grade >= 90) {


console.log("Excellent!");

} else if (grade >= 75) {

console.log("Very good!");

} else if (grade >= 50) {

console.log("Good, but can improve.");

} else {

console.log("You need to work harder.");

Summary

- if: executes code if a condition is true.

- if...else: chooses between two blocks of code.

- if...else if...else: tests multiple conditions in sequence.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy