Mangler.compareType() - DarthJDG/Mangler.js GitHub Wiki

Checks if two values have the same type. Also works with constructors.

Mangler.compareType(first, second)
Parameter Type Default Description
first Any The first value to compare.
second Any The second value to compare.

Returns

Returns true if the two parameters are of the same type, false otherwise.


You can compare any simple JavaScript values or object instances. In addition, you can compare an object instance to its constructor to check if it's of a certain type.

Because of the special treatment of functions as constructors, comparing two functions will return false. You can however compare a value to the Function global to see if it is a function.

The following calls all return true:

Mangler.compareType('A', 'A');
Mangler.compareType(null, null);
Mangler.compareType(1, 2);
Mangler.compareType('A', 'B');
Mangler.compareType(new Date(), Date);
Mangler.compareType(function(){}, Function);
Mangler.compareType({}, Object);
Mangler.compareType([], Array);

Comparing two functions returns false:

Mangler.compareType(function(){}, function(){});
⚠️ **GitHub.com Fallback** ⚠️