2 Little-known things in JavaScript

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

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store