0
const obj = { a: 1, b: 2 }
const keys = Object.getOwnPropertyNames(obj)
keys.forEach(console.log)

(function endWorld() { console.log("Wat") })()

keys.forEach executes, outputting the keys to the log, and then the last line throws an error saying keys.forEach is not a function.

I could work around this but I really want to know why it's happening.

Jaybird
  • 530
  • 4
  • 13
  • 5
    semicolon will fix that - your code (remembering, newline in javascript is just another white space, usually) ... `keys.forEach(console.log)(...)()` ... add semicolon `keys.forEach(console.log);(...)()` - big difference - tip: use semicolons even though they are mainly optional - unless you understand when the are indeed optional – Bravo Aug 20 '21 at 06:51

0 Answers0