One of javascript’s failings is how it inconsistently returns null or undefined. After wasting some time on an issue due to a bad assumption I made, I’ve decided to write down all the places it returns null or undefined or something else.

Copy paste any block and paste into the browser, node, deno, or bun and see for yourself.

Returns undefined

Array.prototype.find

[1,2,3].find(num => num === 4)
// output: undefined 

Returns null

localStorage.getItem

localStorage.getItem('notakey')
// output: null

URLSearchParams: get() method

const params = new URLSearchParams(document.location.search);
params.get("notakey");
// output: null

Returns something else