Search code examples
javascriptcode-formatting

Dangerous implications of Allman style in JavaScript


I cannot remember where, but recently I passed a comment where the user told that 1TBS is more preferred than Allman in JavaScript and said Allman has dangerous implications in JavaScript.

Was it a valid statement? If so, why?


Solution

  • return cannot have LineTerminator after it so:

    return
    {
    
    
    };
    

    is treated as return; (return undefined) instead of return {}; (return an object)

    See the rules for Automatic Semicolon Insertion (ASI) for more.