Javascript Reference
Categories: return

javascript return Description

@March 15, 2008, 1:22 a.m.
returnFirefox/Netscape/NN 2 IE 3 ECMA 1

Stops execution of the current function. A return statement can be located anywhere within the function, including inside control structures. You can optionally specify a value to be returned to the calling statement. This return value can be any JavaScript data type. If a return statement that returns a value is in a loop or other control structure, there must be a return statement for each branch of the execution tree, including a default return statement if execution should reach the main execution scope near or at the end of the function.

 
Example
 
function validateNumber(form) {
    var oneChar;
    for (var i = 0; i < userEntry.length; i++) {
        oneChar = form.entry.value.charAt(i);
        if (oneChar < "0" || oneChar > "9") {
            return false;
        }
    }
    return true;
}

Powered by Linode.