JSFiddle - React, Tailwind, and code Playground
JavaScript
function count(obj) {
return Object.keys(obj).length
}
function var_type(variable)
{
if(variable === undefined){
return 'Undefined';
}
var type = Object.prototype.toString.call(variable).split(' ')[1].slice(0, -1);
if(['Boolean', 'Null', 'Number', 'String', 'Function', 'Array', 'Object'].indexOf(type) >=0){
return type;
}
if(variable.hasOwnProperty('length') && (count(variable) == 0 || (count(variable) == variable.length))){
return 'Array-like';
}
return 'Undefined';
}
console.log(var_type([]));
console.log(var_type(true));
console.log(var_type(null));
console.log(var_type(3));
console.log(var_type('3'));
console.log(var_type(function(){}));
console.log(var_type([4, 4, 4]));
function test()
{
console.log(var_type(arguments));
}
test();
test('ololo');
console.log(var_type(undefined));