Skip to content

Commit b6eb718

Browse files
committed
Fix TypeError in author.js by using Object.values() to iterate over object properties
1 parent f92f622 commit b6eb718

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎Sprint-2/debug/author.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Predict and explain first...
22

3+
/* Prediction - TypeError: author is not iterable.
4+
5+
Explaination - The "for... of" loop is designed fir iterable objects like arrays, strings, maps or sets,
6+
which have built in protocols. plain javascript objects like "author" are not iterable by default,
7+
which would cause the error when the "for... of" loop is used. */
8+
39
// This program attempts to log out all the property values in the object.
410
// But it isn't working. Explain why first and then fix the problem
511

@@ -11,6 +17,6 @@ const author = {
1117
alive: true,
1218
};
1319

14-
for (const value of author) {
20+
for (const value of Object.Values(author)) {
1521
console.log(value);
1622
}

0 commit comments

Comments
 (0)