-
-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathauthor.js
More file actions
18 lines (15 loc) · 686 Bytes
/
author.js
File metadata and controls
18 lines (15 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Predict and explain first...
// This program attempts to log out all the property values in the object.
// But it isn't working. Explain why first and then fix the problem
// The code is trying to iterate over the properties of the author object using a for...of loop, which is not correct for objects in JavaScript.
// In JavaScript, objects are not iterable with for...of loops. Instead, we can use a for...in loop to iterate over the property names of the object, and then access the corresponding values.
const author = {
firstName: "Zadie",
lastName: "Smith",
occupation: "writer",
age: 40,
alive: true,
};
for (const key in author) {
console.log(author[key]);
}