See the next snippet of code:
var arr = [];
arr.length = 10;
// The next statement shows [] in the console.
console.log(arr);
// The next statement shows [undefined × 10] in the console.
arr;
// The next statement shows undefined in the console.
console.log(JSON.stringify(arr[0]));
console.log(JSON.stringify(arr));
[null,null,null,null,null,null,null,null,null,null]
__match_answer_and_solution__
When JSON.stringify is called it call toJSON method of object but undefined is not an object itself then it calls the object that is in the backend of undefined, returning 'null' as value, this is the reason of undefined == null is true.
__match_answer_and_solution__
console.log(arr.toString());
",,,,,,,,,"
__match_answer_and_solution__
When the toString of arr is called it returns an empty string for each undefined value in the array.
__match_answer_and_solution__