Which of the following is a valid `if` statement in JavaScript?
A
if x > 5 then {} B
if (x > 5) {} C
if x > 5 {} D
if [x > 5] {}
Analysis & Theory
`if (x > 5) {}` is the correct syntax for an `if` statement in JavaScript.
What is the correct way to write an `else` statement?
A
else x == 0 B
else: {} C
else {} D
else then {}
Analysis & Theory
`else {}` is the correct way to write an else block.
Which keyword is used to create a switch block in JavaScript?
A
case B
match C
select D
switch
Analysis & Theory
`switch` is the keyword used to start a switch-case block.
What does the `break` statement do in a loop?
A
Skips the current iteration B
Jumps to the start of the loop C
Stops the loop entirely D
Continues the loop
Analysis & Theory
`break` is used to exit a loop immediately.
What does the `continue` statement do?
A
Breaks the loop B
Skips the rest of the current iteration C
Repeats the last iteration D
Ends the function
Analysis & Theory
`continue` skips the current loop iteration and moves to the next one.
Which of the following is a correct `for` loop syntax?
A
for x to 5 {} B
for (x = 0; x < 5; x++) {} C
for x = 0; x < 5; x++ {} D
for (x < 5; x++) {}
Analysis & Theory
`for (x = 0; x < 5; x++) {}` is the correct syntax for a `for` loop.
Which loop is guaranteed to run at least once?
A
for loop B
while loop C
do...while loop D
switch loop
Analysis & Theory
`do...while` loop runs the code block once before checking the condition.
Which statement is used to stop executing a function?
A
stop B
exit C
return D
end
Analysis & Theory
`return` stops the function and optionally returns a value.
What happens if an `if` block has no condition?
A
Error B
Always runs C
Never runs D
Undefined
Analysis & Theory
An `if` statement must have a condition in parentheses — otherwise, it causes a syntax error.
Which keyword is used to define a function in JavaScript?
A
function B
def C
method D
func
Analysis & Theory
`function` is the correct keyword to define a function in JavaScript.