What is a conditional statement?
A statement that executes code only if a specific condition is true.
What keyword is used for a basic condition?
The if keyword. Example: if (x > 10) { console.log('big'); }
How do you add an alternative condition?
Use else if. Example: if (x > 10) {...} else if (x > 5) {...}
How do you provide a fallback for when no conditions are true?
Use else. Example: if (...) {...} else {...}
What is the ternary operator?
A shorthand for if...else. Example: let msg = age >= 18 ? 'Adult' : 'Minor';
How do you compare values strictly?
Use === and !== for strict equality and inequality (compares type and value).
What is the difference between == and ===?
== compares values after type conversion; === compares both type and value.
How do you check multiple conditions?
Use logical operators && (AND), || (OR), and ! (NOT). Example: if (x > 0 && y > 0)
How do you use a switch statement?
Use switch(expression) with case labels. Example: switch(day){ case 'Mon': ... break; }
Why is break used in a switch statement?
To prevent fall-through (stops execution of the next case).
What does default do in a switch statement?
It defines the code to run if no case matches.
What is short-circuit evaluation?
When JavaScript stops evaluating as soon as the result is known. Example: true || false returns true immediately.
What is a loop?
A control structure that repeats code until a condition is false.
What is a for loop used for?
To run code a specific number of times. Example: for (let i = 0; i < 5; i++) {...}
What are the three parts of a for loop?
Initialization, condition, and increment. Example: for (let i=0; i<10; i++)
What is a while loop?
Runs code while a condition is true. Example: while (count < 5) {...}
What is a do...while loop?
Executes code at least once before checking the condition. Example: do {...} while (x < 5);
What does the break statement do in loops?
Immediately exits the loop.
What does the continue statement do?
Skips the current iteration and moves to the next one.
How do you loop through an array?
Use a for loop or .forEach(). Example: arr.forEach(item => console.log(item));
How do you loop through object properties?
Use a for...in loop. Example: for (let key in obj) {...}
How do you loop through iterable objects like arrays?
Use a for...of loop. Example: for (let value of arr) {...}
What is the difference between for...in and for...of?
for...in iterates over keys (indexes), for...of iterates over values.
How do you exit multiple nested loops?
Use labels with break. Example: break outerLoop;