JSFiddle - React, Tailwind, and code Playground

by mickeyvip

HTML

<h3>Better typeof</h3>
<ul id="typeofList">
    
</ul>

CSS

body {
    font-family: Arial, Sans-Serif;
}

#typeofList li {
    font-family: Courier New, monotype;
}

JavaScript

function betterTypeOf( input ){
    return Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1];
}

var s = "I am a string";
var i = 1;
var d = 1.5;
var a = [1, 2];
var o = { name: 'I am an object' };
var f = function(arr) { alert("I am a function"); };

var typeofList = $("#typeofList");
typeofList.append($("<li>betterTypeOf(" + s + "): <b>" + betterTypeOf(s) + "</b></li>"));
typeofList.append($("<li>betterTypeOf(" + i + "): <b>" + betterTypeOf(i) + "</b></li>"));
typeofList.append($("<li>betterTypeOf(" + d + "): <b>" + betterTypeOf(d) + "</b></li>"));
typeofList.append($("<li>betterTypeOf(" + a + "): <b>" + betterTypeOf(a) + "</b></li>"));
typeofList.append($("<li>betterTypeOf(" + o + "): <b>" + betterTypeOf(o) + "</b></li>"));
typeofList.append($("<li>betterTypeOf(" + f + "): <b>" + betterTypeOf(f) + "</b></li>"));