The return statement exits the function immediately:
function checkAge(age) {
if (age < 0) {
return "Invalid age"
}
if (age < 18) {
return "Minor"
}
return "Adult"
}
Once return executes, the function ends. No code after it runs. This enables the guard clause pattern you learned earlier.