Search code examples
javascriptif-statementlogic

The purpose of : "if(boolean) return;". in Javascript


Consider the following code:

if(boolean) return;

What is the purpose if this condition?

Is it logically the same as:

if(boolean) { return true; }

Thank you for answering!


Solution

  • return; with no value is equivalent to return undefined;. But it's usually used in functions that aren't expected to return a value, so it just means "exit the function now".

    So that code is equivalent to:

    if (boolean) {
        return undefined;
    }