In Javascript, is there any way to check the types of a function’s arguments? I want to write a function called checkTypes that does the following:
function checkTypes(typeArr){
//if the types do not match typeArr, throw an error
}
function exampleUsage(arr1, arr2, num1){
checkTypes("object", "object", "number");
//throw an error if the types do not match the corresponding elements
}
You can use the the
typeOffunction adapted from this post Fixing the JavaScript typeof operator combined with this function: