JS Input/Output Solution 6

What will be the output?

1
2
3
 let arr = [];
 arr[0] = 'a';
 console.log(arr['0'] === arr[0]);   // ?

Solution

1
2
3
 let arr = [];
 arr[0] = 'a';
 console.log(arr['0'] === arr[0]);   // true

Why passing index value as string or number to an array variable returns same value?

This is because, index value passed to an array gets converted to a number internally. So, arr['0'] will be interpreted as arr[0]