• Post author:
  • Post category:Blog
  • Reading time:3 mins read
  • Post last modified:June 12, 2024

Examine the following code:

let car = {make: "Citroen", model: "DS"};
for (let f in car)
console.log(f);

What will appear on the console as a result?

  • "Citroen" "DS" 
  • "make: Citroen" "model: DS" 
  • "car" 
  • "make""model"
Explanation & Hint:

The code utilizes a for…in loop to iterate over the properties of the car object. In each iteration, the loop variable f represents the current property name being iterated. The console.log(f) statement logs the value of f to the console. Since the car object has two properties, “make” and “model”, the for…in loop will iterate over these properties, and the respective property names will be displayed in the console: “make” and “model”.

For more Questions and Answers:

JavaScipt Essentials 1 (JSE) | JSE1 – Module 4 Test Exam Answers Full 100%

 

Examine the following code:

let steps = [3, 2, 1];
for (let n of steps)
console.log(n);

What will appear on the console as a result?

  • 1 2 3
  • "[3, 2, 1]"
  • 3 2 1
  • 0 1 2
Explanation & Hint:

The code utilizes a for…of loop to iterate over the elements of the steps array. In each iteration, the loop variable n represents the current element of the array being iterated. The console.log(n) statement logs the value of n to the console. Since the steps array contains three elements [3, 2, 1], the for…of loop will iterate over each element, and the respective values will be displayed in the console: 32, and 1.

For more Questions and Answers:

JavaScipt Essentials 1 (JSE) | JSE1 – Module 4 Test Exam Answers Full 100%

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments