2 Little-known things in JavaScript

Suchen
1 min readMar 13, 2021

I recently started to re-learn JavaScript from basics, so I found two quite mysterious things, which I never watched in any tutorial or read in a book before.

1 — Infinite-Arrays

let sequence = [1,2,3];
sequence.push(sequence);
console.log(sequence[3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3]);// just go on forever.

First we made an array with three elements in it. Then we pushed the array to itself. Now you can forever access the array on its last element, it won’t give any errors; Try to run a for loop on the sequence array it may give you a little surprise. :);

2 — A little quine with array.reduce() method

const filtered = [2,4,10].reduce((a , b) => a + b,(a , b) => a + b + " ");console.log(filtered); // (a , b) => a[0] + b[0] + " "2410;

Instead of giving initial any initial value to the .reduce() method, we gave it an arrow function, and thus it prints out itself in the console, with the result. Well that’s all I have for you today, see you next time.

Adios5

--

--

Suchen

a Software Engineer and obsessed with Programming. And lover of writing about Programming.