判断undefined
function judgeUndefined (arg) {
if ( typeof arg === 'undefined') {
console.log('undefined')
}
}
judgeUndefined(undefined)
判断null
法一
function judgeNull (arg) {
if ( !arg && typeof arg !== 'undefined' && arg != 0) {
console.log('null')
}
}
judgeNull(null)
法二
function getType (obj) {
let type = Object.prototype.toString.call(obj)
return type.split(' ')[1].replace(']', '')
}
console.log(getType([])) // Array
console.log(getType(null)) // Null