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’t seem to return anything.
function render() {
if (object.loading) return; // there is no value after return
// Loading is a boolean indicating if information is still being parsed from a file or not
}
This is the first time I’m seeing code that has a return statement without a succeeding variable specified to be returned after it.
Without the return the program fails so its definitely important it is there.
Does JavaScript have a special situation in which return can be used without specifying what is being returned after it?
If you use
returnwith no value after it, it returns the valueundefined. This is used to stop a function without returning a value. A function will also returnundefinedif it ends without a return statement.http://jsfiddle.net/Q9UJg/1/