I have a function, which receives 2 params: a variable, and a string representation of a data type ('String', 'Object' etc):
function typeChecker(variable, dataType) {
// checks type, returns true or false
}
I want to convert the second parameter to a constructor, so that this expression does not throw an error:
variable instanceof 'Date'
Question: Is it possible to convert any of these:
'String'
'Date'
'Object'
To these:
String
Date
Object
typeChecker({}, Object)is possiblewindoworglobalis a better optiontypeofsince was not sure about performance implications of using instanceof when not necessary.