Is it valid for a render to have more than one return statement within it?

Question

In the context of this exercise, we have multiple return statements inside of render(), but is this valid?

Answer

Yes, this is valid. Each return statement is nested inside of an if or else code block, meaning that only one of the code blocks will ever run on a render(), and so only one of the several return statements will run. The render() function has no limit to how many of these return statements can be inside of it, but only one will ever run at a time.

12 Likes