Although return is commonly used, it isn’t mandatory to use the return keyword. We can still call the function and the code within the function will be executed.
Or is your question how the array is mutated without the use of the return keyword?
Not quite. If you look at the first screenshot you posted, you’ll see that it says this:
A common mistake is to forget the
returnkeyword, in which case the function will return
As such, the
return keyword isn’t strictly required if you don’t need the function to return any data back to the caller.
In this case, since
addFlower() is directly acting on the
flowers array it can do its job without returning a value.
Does that help?
Just to the point. Got it. Thanks.
This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.