Unlike strongly typed languages, JavaScript does not enforce a return type on a function. This means that different paths through a function can return different types of values, which can be very confusing to the user and significantly harder to maintain.
In particular a function, in JavaScript, will return undefined in any of the following cases:
return statement. return with no value. This rule verifies that return values are either always or never specified for each path through a function.
function foo(a) { // Noncompliant, function exits without "return"
if (a == 1) {
return true;
}
}
function foo(a) {
if (a == 1) {
return true;
}
return false;
}