How function is called without using 'return' keyword inside that function?

I am attaching what I learnt from “Function” section of Javascript course.
But in the “Array” section of Javascript course, how function is called without using “return” keyword inside the function?

1 Like

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?

1 Like

I understood how array is mutated. But could not understand how function addFlower(arr) is called without using ‘return’ keyword in the function. Because what I learnt from “Function” section of Javascript course is that: we must have to use ‘return’ keyword inside the function to call that function later on.

1 Like

Hi @dev6300938908

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 return keyword, in which case the function will return undefined by default.

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?

1 Like

Just to the point. Got it. Thanks.

1 Like

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