and Answers Latest Update Already
Passed
What is a common way to prevent infinite loops?
✔✔ Ensure the loop condition eventually becomes false.
What does a `for...of` loop iterate over?
✔✔ The values of an iterable object, like an array.
How can you execute a block of code multiple times without using a loop?
✔✔ Use recursion.
What happens if a `while` loop's condition is always `true`?
✔✔ It creates an infinite loop unless `break` is used.
What does the `finally` block do in a `try...catch` statement?
✔✔ It executes code regardless of whether an error occurs.
1
,What is the difference between `for...in` and `for...of` loops?
✔✔ `for...in` iterates over object properties, while `for...of` iterates over values of an iterable.
What will be printed by `if (5 > 3) console.log("A"); else console.log("B");`?
✔✔ A
How can you skip an iteration in a loop without exiting it?
✔✔ Use the `continue` statement.
What happens if there is no `default` case in a `switch` statement?
✔✔ Nothing happens if no case matches.
How many times will `for (let i = 1; i < 4; i++) { console.log(i); }` execute?
✔✔ Three times.
What is the result of `if (undefined) { console.log("Yes"); } else { console.log("No"); }`?
✔✔ No
2
, What will be the output of `if ("false") { console.log("Truthy"); } else { console.log("Falsy"); }`?
✔✔ Truthy
What is the purpose of a loop condition?
✔✔ To determine whether the loop should continue executing.
How do you prevent a `do...while` loop from executing infinitely?
✔✔ Ensure the condition eventually evaluates to `false`.
What is the effect of `return` inside a loop in a function?
✔✔ It exits the loop and the function immediately.
What will happen if a `while` loop's condition never becomes false?
✔✔ The loop will run indefinitely, causing an infinite loop.
What does the `break` statement do inside a loop?
✔✔ It immediately exits the loop, skipping any remaining iterations.
3