I\'ve been writing JavaScript for quite a long time now, and I have never had a reason to use null
. It seems that undefined
is always preferable an
A few have said that it is ok to initialise objects to null
. I just wanted to point out that destructuring argument defaults don't work with null
. For example:
const test = ({ name } = {}) => {
console.log(name)
}
test() // logs undefined
test(null) // throws error
This requires performing null
checks prior to calling the function which may happen often.