IF Else Introduction in Javascript Basic
buayaberdiri.blogspot.com - In programming, conditional statements are used to make decisions based on certain conditions. In JavaScript, the if-else statement is one of the most fundamental and widely used conditional statements. The if-else statement evaluates a condition and executes one block of code if the condition is true, and another block of code if the condition is false. In this article, we will take an in-depth look at the if-else statement in JavaScript.
Syntax of the if-else Statement
The basic syntax of the if-else statement in JavaScript is as follows:
if (condition) {
// code to be executed if the condition is true
} else {
// code to be executed if the condition is false
}
The condition in the if statement is a boolean expression that is evaluated to either true or false. If the condition is true, the code block inside the if statement is executed. If the condition is false, the code block inside the else statement is executed.
Here is an example:
let age = 18;
if (age >= 18) {
console.log("You are an Big.");
} else {
console.log("You are not an Small yet.");
}
In this example, the age variable is assigned the value of 18. The if statement checks whether age is greater than or equal to 18. Since age is equal to 18, the condition is true, and the code inside the if statement is executed. The output of this code is You are an adult.
Nested if-else Statements
You can also use nested if-else statements in JavaScript. A nested if-else statement is a statement inside another if or else statement. Here is an example:
let grade = 70;
if (grade >= 90) {
console.log("A");
} else {
if (grade >= 80) {
console.log("B");
} else {
if (grade >= 70) {
console.log("C");
} else {
console.log("F");
}
}
}
In this example, the grade variable is assigned the value of 70. The first if statement checks whether grade is greater than or equal to 90. Since grade is less than 90, the else statement is executed. The second if statement checks whether grade is greater than or equal to 80. Since grade is less than 80, the else statement is executed again. The third if statement checks whether grade is greater than or equal to 70. Since grade is equal to 70, the code inside this if statement is executed, and the output of this code is C.
While nested if-else statements can be useful in certain situations, they can also make your code difficult to read and understand. To avoid this, you can use the switch statement instead.
Else IF Introduction in Javascript Basic
In programming, conditional statements are used to make decisions based on certain conditions. In JavaScript, the if-else statement is one of the most fundamental and widely used conditional statements. However, in some cases, we need to test for more than two possible outcomes. This is where the else if statement comes in. In this article, we will take an in-depth look at the else if statement in JavaScript.
Syntax of the else if Statement
The else if statement is an extension of the if-else statement. It allows you to check for multiple conditions and execute different code blocks based on each condition. The basic syntax of the else if statement in JavaScript is as follows:
if (condition1) {
// code to be executed if condition1 is true
} else if (condition2) {
// code to be executed if condition2 is true
} else {
// code to be executed if neither condition1 nor condition2 is true
}
The else if statement allows you to test for multiple conditions. If the first condition is false, it moves on to the next condition and so on until a condition is found to be true. If none of the conditions are true, the code block inside the else statement is executed.
Here is an example:
let grade = 80;
if (grade >= 90) {
console.log("A");
} else if (grade >= 80) {
console.log("B");
} else if (grade >= 70) {
console.log("C");
} else {
console.log("F");
}
In this example, the grade variable is assigned the value of 80. The first if statement checks whether grade is greater than or equal to 90. Since grade is less than 90, the else if statement is executed. The second else if statement checks whether grade is greater than or equal to 80. Since grade is equal to 80, the code inside this else if statement is executed, and the output of this code is B.
Chaining Multiple else if Statements
You can chain multiple else if statements to check for more conditions. Here is an example:
let day = "Saturday";
if (day === "Monday") {
console.log("Today is Monday");
} else if (day === "Tuesday") {
console.log("Today is Tuesday");
} else if (day === "Wednesday") {
console.log("Today is Wednesday");
} else if (day === "Thursday") {
console.log("Today is Thursday");
} else if (day === "Friday") {
console.log("Today is Friday");
} else if (day === "Saturday") {
console.log("Today is Saturday");
} else {
console.log("Today is Sunday");
}
In this example, the day variable is assigned the value of Saturday. The code block inside the else if statement that matches the value of day is executed, and the output of this code is Today is Saturday.
The switch Statement
The switch statement is another way to implement conditional logic in JavaScript. The switch statement evaluates an expression and compares it to multiple cases. If the expression matches a case, the code inside that case is executed. Here is the syntax of the switch statement:
switch (expression) {
case value1:
// code to be executed if expression matches value1
break;
case value2:
// code to be executed if expression matches value2
break;
default:
// code to be executed if expression doesn't match any value
break;
}
In the switch statement, the expression is evaluated, and the code inside the case that matches the expression is executed. If the expression
See the article about javascript here:
- Learn Array Method - forEach, map, reduce, filter
- Learn Basics Array In Javascript
- Learn Basics Asynchronous In Javascript
- How To Change String Value Using Replace in Javascript
- How to Learn a Calculator Basic in Javascript
- What Are Switch in Javascript And How to Use Them
- Create a Calculator Using the Python Flask Framework
- Basic Learning to Make a Calculator With PHP and HTML
- How to Use a FOR Loop in Javascript
- Introduction Objects Basics in Javascript
Check out other articles about HTML & CSS:
- Learn Input Types In HTML For Login And Register Form
- Learn HTML List - How To Create Square, Circle, Number List
- How To Create Comments Line In HTML
- How to Add Text Formatting In HTML
- Adding The Fieldset Code To The Form In HTML
- How to Create a Search Box in Pure HTML
- Create Color Charts With Pure HTML
- How to change font size using CSS
- Types of Border Styles in CSS Code
- How to Change the Background Color in CSS
List of Article Posts https://buayaberdiri.blogspot.com
- What is Breadcrumb Navigation For Website
- What is Rank Math Plugin in Wordpress
- Creating an author account in WordPress
- Configuring your domain and hosting with GoDaddy and WordPress
- How to create a sitemap in google search console
- Why A Sitemap On A Website Is So Important
- How to get your website approved by google adsense
- What is Domain Authority (DA) Website And How To Increase
- How Does CPM Work in Google Adsense And Differents With CPC
- Rejection of Google Adsense approval due to low value content, how to fix ?
- What is Google Spam Update And Impact To Your Website
- Admin Executive Jobs in MYLIFESTYLE HOLDINGS PTE. LTD
- Engineer Assistant Jobs Daifuku Mechatronics (S) Pte Ltd
- Customer Service Officer Jobs In Lending Bee Pte Ltd
- Clinic Executive Jobs in The Orthopaedic Centre (TOC)
- Student Recruitment Jobs in Singapore University of Social Sciences
- Healthcare Assistant Jobs in Acumed Medical Pte Ltd
- Operator Jobs in CMC Materials Singapore Pte. Ltd
- Assistant Housekeeping Manager Jobs in Four Seasons Hotel Singapore
- Office Cleaner Jobs in PERSOLKELLY Singapore Pte Ltd
- Line Room Attendant Jobs in Paradox Hotel
- Housekeeping Supervisor Jobs in Copthorne King's Hotel
- Housekeeper Jobs in Pure Group (Singapore)
- Risk Management Group Jobs in DBS Bank Limited
- Cloud Specialist Jobs in DBS Bank Limited
- DBS Bank Limited : Job Vacancies, Address, Contact
- Administrative Assistants Jobs in Tan Eng Huat Motor
- Customer Service Jobs in Tien Hsia Language School
- Customer Service Jobs in Yong Fah International Pte Ltd
- Administrative Officer Part time Jobs in SDC
- Warehouse Assistant Job Vacancy in Okonz Pte. Ltd
- Ringkasan Tentang Tujuan Dari Manajemen Keuangan
- Pengertian dan Konsep Dasar Keuangan
- Lowongan Operator Dan Staff PT Andalan Sapta Mandiri
- Lowongan Kerja SMA SMK D3 dan S1 Terbaru
- Lowongan PT Garuda Metal Utama Posisi Operator & Staff
- Lowongan Operator dan Staff PT Samudra Utama Narapati
- Lowongan Kerja Staff Produksi PT Citra Sinergi Jakarta
- Lowongan Kerja PT Maxxis International Indonesia Posisi Operator dan Staff
- Lowongan PT Tongcheng Magnet Wire Posisi Operator dan Staff
- Lowongan Kerja Operator Produksi PT Intera Lestari Polimer
- Lowongan Kerja PT NSK Bearings Posisi Production Specialist
- Lowongan Kerja Staff QA PT Tirta Alam Segar (TAS)
- Lowongan Operator Maintenance PT TUFFINDO NITTOKU AUTONEUM
- Lowongan Kerja Staff Produksi di PT Panasonic Gobel
- Lowongan Kerja Operator Produksi di PT Delcoprima Pacific
- Lowongan PT PQ Silicas Indonesia Posisi Utility Operator
- Lowongan Kerja Dailywell Posisi Staff Produksi & Operator Mesin
- Lowongan Maintenance Manager di PT Lotte Indonesia
- Lowongan Kerja Operator Forklift di PT Lotte Indonesia
- Lowongan Kerja Operator Produksi PT Eslar Utama
- Lowongan Kerja Administrasi Di PT Kalbe Farma Tbk
- Lowongan Kerja PT Excel Metal Industry Melalui Email dan Website Resmi
- Lowongan Kerja Network Engineer di Bank BCA
- Lowongan Kerja Database Engineer di Bank BCA
- Lowongan Kerja Application Developer di Bank BCA
- Lowongan Kerja Data Center System Bank BCA
- Lowongan Kerja DevOps Engineer di Bank BCA
- Lowongan Kerja Operator dan Non Operator PT TSSI
- Lowongan Kerja Quality Control Staff di Pabrik Baterai ABC
- Lowongan Kerja Staff Admin di PT Bevananda Mustika
- Lowongan Kerja Staff PPIC di PT Allure Alluminio
- Lowongan Kerja PT Lion Wings Posisi Staff Produksi
- Lowongan Kerja PT. Schlemmer Automotive Indonesia
- Lowongan Kerja Staff Teknik di PT HPPM (Honda Precision Parts Manufacturing)
- Lowongan Pekerjaan PT ARYA XPRESS Posisi Supir Expedisi (Driver)
- Lowongan Kerja Driver di PT Akazora Dinamis Mandiri
- Lowongan Kerja PT Mayora Indah Tbk Lewat Email dan Website Resmi
- Lowongan Kerja Driver atau Supir PT Hongfa Electronic Indonesia
- Lowongan Kerja Cleaning Service di CV Hello Klin Indonesia
- Lowongan Pekerjaan PT Sinar Sosro dan Alamat Email
- Lowongan Pekerjaan Operator di PT Tangkas Cipta Optimal (TACO)
- Lowongan Pekerjaan Operator Produksi di PT Tirta Alam Segar
- Info Loker Operator Warehouse di PT Nippo Mechatronics Indonesia
- Lowongan Kerja Staff QC di CV Golden Star Bird Nest
- Lowongan Kerja Posisi TEXTILE ENGINEER di PT Mattel Indonesia
- Alamat Email PT Mattel Indonesia Untuk Melamar Pekerjaan
- Info Loker PT Cendrawasih Pertiwijaya (Blue bird Cijantung)
- Loker Cleaning Service di PT Halilintar Lintas Semesta atau HLS Telecom
- Cara Melamar Pekerjaan Driver di Bluebird Pool Sutoyo
- Loker Driver atau Supir Direksi di PT Panca Budi Pratama
- Loker Supir atau Driver di Style Korean Indonesia
- PT Kiyokuni Indonesia : Info Loker, Alamat Pabrik, BKK
- Cara Melamar Pekerjaan PT Denso Indonesia di Website Resmi
- PT Mesin Isuzu Indonesia : Info Loker, Alamat, Email
- PT MITSUBA INDONESIA PIPE PARTS : Info Loker, Email, Alamat Lengkap
- PT. Shindengen Indonesia : Lowongan Pekerjaan, Email, Alamat Lengkap
- Info Loker PT Suryaraya Rubberindo Industries (SRI) , Alamat, BKK Sekolah
- PT. TUFFINDO NITTOKU AUTONEUM : Info Loker, Email, Alamat Lengkap
- PT Kawasaki Motor Indonesia : Info Loker, BKK Sekolah, Alamat Pabrik
- Info Loker PT EPSON Indonesia : Alamat, Email, Nomor Telepon & Yayasan
- Cara Melamar Pekerjaan di PT AHM : Info Loker, Email, Alamat
- Loker PT Indofood : Lowongan Kerja, Alamat, Email, Nomor Telepon
- PT Yamaha Motor : Lowongan Kerja, Alamat, Nomor Telepon
- PT PLUMBING SOLUSI INDONESIA - Lowongan Kerja, Alamat Dan Email
- PT Cahaya Arif Abadi - Info Loker, ALamat dan Bergerak di bidang apa
- IMF Request to Indonesia to Cancel Ban on Export of Raw Minerals
- How to Implement the Integration AMP in Google Analytics 4
- iOS 17 For iPhone : New Features, Device Support, How to Upgrade
- Elon Musk Investment Plan For Tesla in India and Indonesia