A functional question

i have 2 questions: 1) does it have 2 b only 1 return command on a function?
2) if not how many return commands can a function execute?

1 Like

A function may have more than one return path, but only one will be followed. This is managed using control flow within the function.

function hilomatch(target, value) {
    if (value > target) {
        return "high"
    } else if (value < target) {
        return "low"
    } else {
        return "match"

console.log(hilomatch(Math.floor(Math.random() * 10), 5))
1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.