I have a function with an optional parameter. I'm defaulting the value to 1000 if the parameter isn't supplied like so:
function zoom( coords, zoomSpeed){
zoomSpeed = zoomSpeed || 1000;
//rest of code
}
This works for testing presence of the parameter, but I also want to make sure a number was supplied as the parameter. I'm using the following but it seems like there is a better way to do this.
function zoom( coords, zoomSpeed){
if (typeof zoomSpeed === "number"){
zoomSpeed = zoomSpeed;
}else{
zoomSpeed = 1000;
}
//rest of code
}
Any feedback on a better way to do this would be appreciated.