Evaluating If Statement Execution
What will be logged to the console after executing: if (5 u003E 2) { console.log('Yes'); } else { console.log('No'); }?
- Yes
- Null
- No
- Undefined
- Error
Understanding Else If
Which statement correctly checks if a variable 'score' is greater than 90, and prints 'Excellent' if true, 'Good' if exactly 90, otherwise 'Try again'?
- if (score =u003E 90) { console.log('Excellent'); } else { console.log('Good'); }
- if (score = 90) { console.log('Excellent'); } else { console.log('Try again'); }
- if (score u003E 90) { console.log('Excellent'); } else if (score === 90) { console.log('Good'); } else { console.log('Try again'); }
- if score u003E 90 then console.log('Excellent'); else console.log('Try again');
- if (score u003E= 90) { console.log('Excellent'); } else { console.log('Good'); }
Detecting Switch Syntax
Which of the following is a correct way to start a switch statement in JavaScript?
- switch(variable) {
- switch { variable }
- case (variable) {
- switch: (variable) {
- switch variable {
Case Matching in Switch
When using a switch statement, what happens if none of the case values match the expression?
- The code inside the default block runs, if present.
- The first case block always executes.
- Switch stops all execution in the program.
- An error is thrown.
- The switch block is skipped entirely.
For Loop Basics
Which for loop will correctly print numbers 0 through 4 to the console?
- for (let i = 1; i u003C= 5; i++) { console.log(i); }
- for (var i = 5; i u003E= 0; i++) { console.log(i); }
- for let i = 0; i u003C 5; i++ { console.log(i); }
- for (let i = 0; i u003C 5; i++) { console.log(i); }
- for (i = 0; i u003C 5; i--) { console.log(i); }
While Loop Execution
Given: let x = 3; while (x u003E 0) { x--; } What will be the value of x after the loop finishes?
- undefined
- 1
- 3
- 4
- 0
Do...While Difference
How does a do...while loop differ from a while loop in JavaScript?
- A do...while loop only executes if the condition is true initially.
- A do...while loop will never execute if the condition is false.
- A do...while loop cannot use break.
- A do...while loop can only run for arrays.
- A do...while loop always executes its body at least once.
Using Continue in Loops
If you use 'continue' inside a for loop, what happens to the current iteration?
- Nothing changes; the loop runs as usual.
- An error occurs.
- The current iteration stops, and the loop proceeds to the next iteration.
- All iterations are skipped.
- The loop breaks completely.
Purpose of Break Statement
What is the main purpose of the 'break' statement inside loops?
- To pause the loop and resume later.
- To exit the loop immediately.
- To reverse the loop direction.
- To skip to the end of the current iteration.
- To restart the loop.
For...of Loop Use Case
Which statement best describes the use of a for...of loop in JavaScript?
- It iterates over the properties of an object.
- It loops indefinitely.
- It only works with string types.
- It iterates over numbers from 0 to 10 automatically.
- It iterates over the values of an iterable object like an array.
For...in Loop Application
What does a for...in loop do when used with an object?
- It loops through each element in an array.
- It creates new properties for the object.
- It iterates over the object's enumerable property names.
- It iterates over the object's values.
- It sorts the object's keys alphabetically.
Else Without If
Is it valid to use an else block in JavaScript without a preceding if statement?
- Else can only follow loops.
- No, an else must follow an if statement.
- Else can only follow switch statements.
- Else is not used in JavaScript.
- Yes, else statements can exist independently.
Default Keyword in Switch
In a switch statement, what is the role of the default keyword?
- To specify the first case to check.
- To initialize the switch values.
- To terminate the switch immediately.
- To handle any case not matched by a case label.
- To define a variable inside switch.
Increment in For Loops
In the for loop for (let i = 0; i u003C 5; i++), what does i++ do?
- It decreases i by 1 after each iteration.
- It multiplies i by 2 in each iteration.
- It stops the loop.
- It increases the value of i by 1 after each iteration.
- It checks if i is even.
Breaking Out of Nested Loops
Given two nested for loops, what happens when a break statement is called inside the inner loop?
- It exits both loops.
- It throws an error.
- It exits only the inner loop.
- It pauses all loops.
- It restarts the inner loop.
Checking Truthy and Falsy Values
Which value will cause an if statement if (x) to consider x as false?
- {}
- []
- 0
- 'Hello'
- 10