function checkValType(val){ let type = typeof val; if(type !== 'object') return type; return Object.prototype.toString.call(val).replace(/^\[object (\S+)\]$/, '$1').toLowerCase() } console.log(checkValType('12')) console.log(checkValType({})) console.log(checkValType([]))