Array and Object literals should always be preferred to Array and Object constructors.

Array constructors are error-prone due to the way their arguments are interpreted. If more than one argument is used, the array length will be equal to the number of arguments. However, using a single argument will have one of three consequences:

- If the argument is a number and it is a natural number the length will be equal to the value of the argument.
- If the argument is a number, but not a natural number an exception will be thrown.
- Otherwise the array will have one element with the argument as its value.

For these reasons, if someone changes the code to pass 1 argument instead of 2 arguments, the array might not have the expected length. To avoid these kinds of weird cases, always use the more readable array.

Object constructors don't have the same problems, but for readability and consistency object literals should be used.

## Noncompliant Code Example

    var a3 = new Array(x1); // Noncompliant and variable in results
    var a4 = new Array();  // Noncompliant. Results in 0-element array.
    var a1 = new Array(x1, x2, x3);  // Noncompliant. Results in 3-element array.

    var o = new Object(); // Noncompliant

    var o2 = new Object(); // Noncompliant
    o2.a = 0;
    o2.b = 1;
    o2.c = 2;
    o2['strange key'] = 3;

## Compliant Solution

    var a = [x1, x2, x3];
    var a2 = [x1, x2];
    var a3 = [x1];
    var a4 = [];

    var o = {};

    var o2 = {
      a: 0,
      b: 1,
      c: 2,
      'strange key': 3
    };