What will the output of the for loop be when continue is used for i === 3?

Prepare for the Salesforce JavaScript Developer I Certification Exam. Utilize interactive quizzes, flashcards, and detailed explanations for each question. Boost your confidence and ace your exam effortlessly!

In this context, when a for loop is combined with the continue statement, it allows for the current iteration of the loop to be skipped based on a specified condition. Here, the condition is when i === 3.

When the loop iterates, it checks the value of i during each pass. If i equals 3, the continue statement triggers, and the execution immediately jumps to the next iteration of the loop without executing any subsequent code for that iteration. Hence, the value 3 is effectively omitted from the output.

As the loop runs through a series of integers starting from 1, the following occurs:

  • When i is 1, it prints 1.

  • When i is 2, it prints 2.

  • When i is 3, it encounters the continue statement, thereby skipping the output for this value.

  • For i equal to 4, it prints 4.

Therefore, the output consists of the values that were printed from the loop, which are 1, 2, and 4, leading to the final output being 1 2 4. This aligns with the chosen answer.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy