If Else
Conditional statements allow JavaScript to make decisions.
The main conditional statements are:
- if
- else if
- else
Example
let age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}
Learn JavaScript If Else with simple explanations, practical examples, interview questions, MCQs and hands-on practice.
Understand the concept step by step
Conditional statements allow JavaScript to make decisions.
The main conditional statements are:
let age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}
Try this JavaScript program yourself
let age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}Expected result of the program
Adult
Test your understanding
Don't just read the example. Open your JavaScript editor and write the program yourself. Try changing the values and observe what happens.
Modify the example program and experiment with different values.
Write the same program from scratch without looking at the example.
Test what you learned
Prepare for JavaScript interviews
Interview Question
Answer
JavaScript is a high-level programming language widely used to make web pages interactive and dynamic. It can run in browsers as well as on servers using environments such as Node.js.
Interview Question
Answer
A variable declared with let can be reassigned, while a variable declared with const cannot be reassigned after initialization.
Interview Question
Answer
The DOM, or Document Object Model, represents the structure of an HTML document as objects that JavaScript can read and manipulate.
Chapter 7 of 25
Keep going — you're doing great! 🚀