-(Edited)This question does not apply to only Numbers, but about all types in general. I am using something like:
exampleFunction1(a,b){
if(
Object.prototype.toString.call(a) === "[object Number]" &&
Object.prototype.toString.call(b) === "[object Number]"
){
return a+b;
}else{
console.log('%cType Error : exampleFunction1(<Number>)','color:#00FF66;')
}
}
exampleFunction2(type,length,format) {
if(
Object.prototype.toString.call(type) === "[object String]" &&
Object.prototype.toString.call(length) === "[object Number]" &&
(Object.prototype.toString.call(format) === "[object String]" || Object.prototype.toString.call(format) === "[object Undefined]" )
){
}else{
console.log("%cType Error : exampleFunction2(<String>,<Number>,<String>)","color:#00FF66;")
}
}
in almost all of my functions to strict check its input type before starting to write my actual code. And its mostly on functions that i'll share amongst my team and on my own library which other people will try to use. Is this considered as a good practice or it's unnecessary ?