Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Enumerability

Which properties show up where:

OperationOwnInheritedEnumerable only?
for-inYesYesYes
Object:keysYesNoYes
Object:get-own-property-namesYesNoNo
Reflect:own-keysYesNoNo

The Practical Rule

Use Object:keys or Object:entries with for-of — they enumerate own, enumerable properties, which is what you want 95% of the time. Avoid for-in — it includes inherited properties, which is almost never what you want.

;; Safe: own enumerable properties
(for-of entry (Object:entries obj)
  (console:log entry))

;; Unsafe: includes inherited properties
(for-in key obj
  (console:log key))

Non-enumerable properties are used by the language itself (built-in methods like to-string) and by library code that wants to hide implementation details. You’ll rarely create non-enumerable properties yourself.