I am a new JavaScript programmer and I wanted to ask you if it's possible to store the type of a variable with the typeof() method. You see, I need to build a function that takes a string and checks if it is the same type as the variable.
function typeValidation(variable, type) {
if(typeof(type) == typeof(variable)){
return true; // I am not going to check what the variable says since it's a string, and I have only to check the type of those two.
}else if(type == "boolean" && typeof(type) == Boolean ){ //it won't work but I just want to give you the idea
return true
}
}
console.log(typeValidation("42","number"));