Concise syntax for javascript if statements without curly brackets

后端 未结 5 1544
孤街浪徒
孤街浪徒 2021-01-18 06:56

So pragmatically, I\'ve got a quick and dirty answer to what I\'m looking for here. But why isn\'t using that a good idea? Why can\'t I find any formal documentation of it

5条回答
  •  梦毁少年i
    2021-01-18 07:11

    why isn't using that a good idea?

    It is far to easy to add another statement and expect it to only fire if the if passes

    Why can't I find any formal documentation of it?

    The MDN documentation:

    Statement that is executed if condition evaluates to true. Can be any statement, including further nested if statements. To execute multiple statements, use a block statement ({ ... }) to group those statements.

    ECMA-262 (page 89):

    if ( Expression ) Statement

    It seems that there's an indentation based one

    No. Just an if, then a condition, then a statement. The statement can be formatted on the same line or the next line.

    White space is not significant in JS.

提交回复
热议问题