Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function test() {
// simple return or return void 0 to return undefined
return void 0
}
var x = test()
if (!x) {
console.log('no x! great check') // good
}
if (x === undefined) {
console.log('x === undefined') // good
}
if (typeof x === 'undefined') {
console.log("typeof x === 'undefined'") // good
}
if (typeof x === 'object') {
console.log("typeof x === 'object'") // Yay not seen as an object like 'null'
}
function defaultValueFunc(data = {}) {
return data.id
}
defaultValueFunc(undefined) // fine
defaultValueFunc(x) // fine
try {
defaultValueFunc(null) // NOT fine
} catch (err) {
console.log('Dang it null!')
console.log(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment