Skip to content

Instantly share code, notes, and snippets.

@vaidd4
Created May 21, 2019 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaidd4/279bfa7b378b3dbfd0489df58bd86999 to your computer and use it in GitHub Desktop.
Save vaidd4/279bfa7b378b3dbfd0489df58bd86999 to your computer and use it in GitHub Desktop.
JS handling of undefined & null as object properties
let obj = { a: 'a', b: null, undefined: 'undef', null: 'nil' }
obj['a'] // 'a'
obj[obj.b] // 'nil'
obj[obj.c] // 'undef' (obj.c is undefined)
obj[obj] // undefined
// Can be used for making conditions with objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment