Javascript Developer JSE 40 01 · Free Practice Question Easy

Question 18

Q423 - Control Flow


Examine the following code:


What will appear in the console as a result?


  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: A

Explanation

Topic: for in over object


Try it yourself:


Explanation:

The for in statements combo iterates over the properties of an object.

The code block inside the loop is executed once for each property.

https://www.w3schools.com/jsref/jsref_forin.asp


(There are similar questions Q323 and Q523.)


Q423 (Please refer to this number, if you want to write me about this question.)

A. The code uses a for...in loop to iterate over the properties of the 'car' object. It logs the property names ('make' and 'model') to the console, not the property values.

B. This choice is incorrect because the code is logging the property names ('make' and 'model') of the 'car' object individually, not in the format of "property: value".

C. This choice is incorrect because the code is logging the property names ('make' and 'model') of the 'car' object, not the property values ('Citroen' and 'DS').

D. This choice is incorrect because the code is iterating over the properties of the 'car' object and logging the property names ('make' and 'model'), not the object itself.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need