0

While declaring an array, the JavaScript ignores the last empty/undefined element. What could be the logic and reason behind such implementation in JavaScript language?

(function guessOutput () {
    'use strict';
    var array1 =  [,,undefined,];
    var array2 = [,,undefined];
    console.log(array1.length === array2.length); // returns true. Why?
})();
Aaditya Sharma
  • 2,790
  • 3
  • 23
  • 35
  • 3
    [JavaScript ignores tailing commas in arrays.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas) – Mohammad Usman Apr 29 '19 at 07:37
  • 1
    SOME JavaScript implementations will ignore trailing commas – mplungjan Apr 29 '19 at 07:38
  • You might want to use `null` or `undefined` after the last comma as well. If you do not do this, JavaScript defaults to whatever the implementation of given assignment holds default. – Barrosy Apr 29 '19 at 07:40

0 Answers0