Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 1.12 KB

README.md

File metadata and controls

39 lines (25 loc) · 1.12 KB

67. Symbols and reflection

Learn

  • Symbol
  • well-known symbols
  • Reflect.ownKeys
  • Object.hasOwn

How it works

A Symbol is a unique primitive often used as a property key to avoid naming collisions. Well-known symbols customize language protocols such as iteration. Reflection APIs inspect and operate on objects. Symbols do not make data secret; code with the key can still access it.

Common mistake

JSON.stringify and Object.keys do not include symbol-keyed properties.

Guided challenge

Add string and symbol keys, inspect them with different APIs, and implement a custom Symbol.iterator method.

Further reading

Run the example

Open example.html, inspect example.js, then edit and refresh. For APIs that need an origin, run a local server from the JavaScripts folder.

Completion check

  • Explain the behavior and its limits in your own words.
  • Test a normal case and a failure or cleanup case.
  • Record when this feature is useful and when a simpler approach is better.