Search code examples
javascriptrefactoringternary-operatorshorthandshorthand-if

Shorthand if ? return : null


I want to achieve this:

 if (full) {
      return
    }
    else{
      // nuthin
    }

But shorter, something like:

full ? return : null;

But that doesn't work..

I could do:

if (full) { return }

But I like the ternary more

I expected something like full ? return to work...

I basically want to break out of the current function when the value is true... Are there any better/working shorthands available?


Solution

  • So this is as short as it gets:

     if full return