Guard Clauses

The idea behind returning early is that you write functions that return the expected positive result at the end of the function.

The rest of the code, in the function, should trigger the termination as soon as possible in case of divergence with the function’s purpose.

An early return does exactly as its name implies. This is what an early return looks like:

function someFunction() {
    if (!someCondition) {
        return;
    }    
    // Do something
}

Backlinks