A small point:
line 8 you return
in the if
construct, so the else
and its associated brackets are redundant. This is a very common pattern (it's called a guard )...
myFunction(params) {
if (there's something wrong with the parameters)
return errorvalue;
// no need for an else here, just get on with it!
do rest of function
}