Saturday, November 7, 2020

The array literal notation [] is preferrable

This warning has existed in two forms across the three main linters. It was introduced in the original version of JSLint and has remained in all three tools ever since.


In JSLint and JSHint prior to version 1.0.0 the warning given is "Use the array literal notation []"


In JSHint since 1.0.0 the warning given is "The array literal notation [] is preferrable"


In ESLint the warning has always been "The array literal notation [] is preferrable"


The situations that produce the warning have not changed despite changes to the text of the warning itself.


When do I get this error?

The "The array literal notation [] is preferrable" error (and the alternative "Use the array literal notation []" error) are thrown when JSLint or JSHint encounter a call to the Array constructor preceded by the new operator with no arguments or more than one argument or a single argument that is not a number. Here's an example:


var x = new Array(),

    y = new Array(1, 2, 3),

    z = new Array("not a number");




var x = []; => JSLint found no errors


References:

http://linterrors.com/js/the-array-literal-notation-is-preferrable

1 comment:

  1. -- Living Mobile --: The Array Literal Notation [] Is Preferrable >>>>> Download Now

    >>>>> Download Full

    -- Living Mobile --: The Array Literal Notation [] Is Preferrable >>>>> Download LINK

    >>>>> Download Now

    -- Living Mobile --: The Array Literal Notation [] Is Preferrable >>>>> Download Full

    >>>>> Download LINK 78

    ReplyDelete