Switch Statement Question

I’ve just finished the Switch Statements challenge and have a question about how they work.

In the following function (from the challenge), at what point is the returned string assigned to the answer variable? In other words, How does returning answer give the correct output?

function switchOfStuff(val) {
    var answer = "";

    switch (val) {
        case "a":
             return "apple";
             break;
        case "b":
            return "bird";
            break;
        case "c":
            return "cat";
            break;
        default:
            return "stuff";
            break;
    }
  return answer;  
}

Ahh! That makes sense.

So as it’s written, the answer variable is superfluous. If I wanted to keep the answer variable, I would assign the string to answer (i.e. answer = "apple") rather than to return the string. Got it.

Thank you for the prompt response!