if/else:
The basic conditional structure that executes code blocks based on whether a condition evaluates to true and false.
switch:
Used for multiple conditions. It is cleaner and more readable than multiple if / else if statements in some cases
Ternary Conditional:
A shorthand for if-else.
syntax: condition ? expressionIfTrue : epressionIfFalse
for loopsThe classic loop, allowing fine-grained control over initialization, condition, and iteration.
while loopsRepeats as long as the condition is true. Common Pitfall: Infinite loops if a condition is not properly updated.
do...while loopsExecutes the block at least once before checking the condition.
for...inLoops through the keys (or property names) of an object or array (as an object). It works for objects, arrays, and array-like structures, but the keys are the indices when used on arrays.
Example:
const obj = { a : 1, b : 2, c : 3 };
for (let key in obj) {
console.log(key); // a b c
}
for...ofLoops through the values of iterable objects (like arrays, strings, or maps). It does not give the index or key.
Example: