JavaScript Trick:1
let arr=[1,2,3,4,5];
arr.length=0;
console.log(arr);
Look it carefully , there has an array (arr) with five elements(1,2,3,4,5) . So, initially array length is 5. Now I makes array length to zero using inbuild length function of JavaScript and trying to console. what will be the output ?
The output should be blank array, because I have assigned the array length 0. The array converts into a blank array or empty array.
Now what will happen ?
let arr=[1,2,3,4,5];
arr.length=8;
console.log(arr[6]);
console.log(arr);
Again I am trying to assign array length 8 using JavaScript inbuild length function. Now trying to console 6th element of this array and whole array . what will be output now ?
The output should be [1, 2, 3, 4, 5, empty × 3]. Three empty element are added in the array. Now array will be [1,2,3,4,5,,,]. So, the first output should be undefined . because 6th cell is empty.