README
gettypeof
getTypeOf - The Smartest way to get Type* in JavaScript
Install
Use
import typeOf from "gettypeof"
var x = "hello";
if(typeOf(x) === "String"){
//This will be True
}
Input Output Table
Run | Output | |
---|---|---|
Undefined | typeOf() |
Undefined |
typeOf(undefined) |
Undefined | |
Class | typeOf(new Person("Narendra")) |
Person |
typeOf(new Employee("Deepak", "Developer")) |
Employee | |
typeOf(new Date()) |
Date | |
typeOf(Symbol("foo")) |
Symbol | |
String | typeOf("") |
String |
typeOf("---") |
String | |
Null | typeOf(null) |
Null |
Object | typeOf({name: "Narendra"}) |
Object |
typeOf({}) |
Object | |
Number | typeOf(3.4) |
Number |
Boolean | typeOf(true) |
Boolean |
Array | typeOf([]) |
Array |
typeOf([1,2,3,4]) |
Array | |
NaN | typeOf(0/0) |
NaN |
typeOf(NaN) |
NaN | |
Function | typeOf(parseInt) |
Function |
typeOf(()=>{}) |
Function |
Example setup for above test cases !
class Person {
constructor(name) {
this.name = name;
}
}
class Employee extends Person {
constructor(name, job) {
super(name);
this.job = job;
}}