Why use {} instead of new Object() and use [] instead of new Array() and true/false instead of new Boolean()?

后端 未结 5 1090
南方客
南方客 2020-12-06 00:55

Many people say that you should avoid new Object, new Array()and instead use {}. [], and true/false.

What are the benefits of using the literal constructs to get a

5条回答
  •  有刺的猬
    2020-12-06 01:46

    I think it's mostly about succinctness.

    Why write new Array() when you can write [], or new Object() when you can write {}?

    Also new Boolean() is entirely redundant. A boolean is always going to need to be either true or false, so you should definitely use the built in constants for that.

提交回复
热议问题