Skip to content Skip to sidebar Skip to footer

Return Function In Javascript And How It Works?

I'm trying to optimize and existing piece of WebGl JavaScript code, and the bottleneck of the code is at an if statement with return at the end however, the return statement doesn'

Solution 1:

If you use return with no value after it, it returns the value undefined. This is used to stop a function without returning a value. A function will also return undefined if it ends without a return statement.

http://jsfiddle.net/Q9UJg/1/

Solution 2:

It is used in this case like a get out clause, simple breaking out of the execution of the function prematurely because a required condition has not been met. Is that the entire function or is there more after the comment?

Solution 3:

There is nothing wrong with not returning a value. In your example it just means that the function finishes executing on that line: code after the return is not executed if that conditional is true.

Post a Comment for "Return Function In Javascript And How It Works?"