While you are right, that checking for falsy has a couple of drawbacks if the map contains vaues like false, 0, "", ..., using your suggested approach is also not correct for checking if an object property exist.

To check if a property exists you need to check via https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty.

Your approach of using obj['prop1'] !== undefined or typeof obj['prop1'] !== 'undefined' doesn't allow an entry of the map to have the value undefined.

Not having a straight forward interface for checking if a key exists in a map is one more reason to use Map instead of a plain object.

Software Engineer 🚀 JavaScript 👾 TypeScript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store