Skip to content

Instantly share code, notes, and snippets.

View Sheraff's full-sized avatar

Flo Sheraff

View GitHub Profile
@Sheraff
Sheraff / nothing.js
Created February 2, 2021 20:42 — forked from joakim/nothing.js
The concept of nothing in JavaScript (Crockford's idea of a better undefined)
const nothing = new Proxy(Object.freeze(Object.create(null)), Object.create(null, {
get: { value(target, property) {
return property === Symbol.toPrimitive ? () => null : nothing }
}
}))
nothing.foo === nothing // true
nothing.foo.bar.baz[42].qux // nothing forever
typeof nothing === "object" // true