30 JavaScript interview/practice questions focused on if, else if, and else statements, from basic to a bit tricky
February 3, 2026 in Education
🟢 Basic Level (1–10)
- What is an
if statement in JavaScript?
- Write a program to check if a number is positive.
- How do you check if a number is even or odd using
if?
- What is the syntax of
if...else in JavaScript?
- Write a program to check if a person is eligible to vote.
- What happens if the condition inside
if is false?
- Can we use multiple
if statements without else?
- Write a program to check whether a number is greater than 100.
- How do comparison operators work in an
if condition?
- What is the difference between
== and === in an if statement?
🟡 Intermediate Level (11–20)
- Write a program to find the largest of two numbers using
if.
- Write a program to find the largest of three numbers using
if...else if.
- How do logical operators (
&&, ||, !) work inside if conditions?
- Write a program to check whether a year is a leap year.
- What is nested
if? Give an example.
- How does JavaScript treat non-boolean values in
if conditions?
- What are truthy and falsy values? Name at least 5 falsy values.
- Write a program to check if a character is a vowel.
- What is the difference between
if...else if and switch?
- Write a program to check whether a user is an adult and has a driving license.
🔴 Advanced / Tricky (21–30)
- What will be the output?
if ("0") {
console.log("True");
} else {
console.log("False");
}
- What will be the output?
if (0 == false) {
console.log("Equal");
}
- What will be the output?
if (null) {
console.log("Yes");
} else {
console.log("No");
}
- What will be the output?
if (undefined == null) {
console.log("Same");
}
- Can an
if statement exist without curly braces {}? Explain.
- What is short-circuit evaluation in
if conditions?
- How can you replace a simple
if...else with a ternary operator?
- Write a program that checks multiple conditions in a single
if statement.
- What is the scope of variables declared inside an
if block?
- What are common mistakes developers make while using
if statements in JavaScript?