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 new instance of an Object or Array rather than using new? I konw that Crockford doesn’t like new but is that the main argument?
The advantages of object and array literals over using the respective constructors are:
ArrayorObjectconstructors have been overriddenIn the case of arrays, there’s an additional advantage of a literal: it’s impossible to create an array with a single member using the
Arrayconstructor alone. For example,[3]will create an array with one element which is the number 3, whilenew Array(3)creates an array of length 3.Update: the following paragraph is no longer relevant now the question has been edited.
Regarding Booleans, you seem to have a misconception:
new Boolean(false)is not the same asfalse. TheBoolean()constructor creates a Boolean object whereasfalseandtrueare Boolean primitives. In fact,new Boolean(false)evaluates totruewhen coerced into a Boolean in, for example, anifstatement. In short, there’s very rarely a reason to use theBoolean()constructor. Usetrueandfalseinstead. Similarly, other primitives such as strings and numbers have correspondingString()andNumber()constructors that produceStringandNumberobjects that are different to primitive strings and numbers and should generally be avoided.