let elements = document.querySelectorAll(".test"); // selecting all HTML elements with class of 'test'm return array-like object
let elementsArray = Array.prototype.slice.call(elements); // convert array-like object to array
So whats the difference between this: let elementsArray = Array.prototype.slice.call(elements);
and this: let elementsArray = Array.slice.call(elements);
How calling some method from prototype object helps?
When you ask tempArray for its slice method, JavaScript: checks tempArray to see if it has a method called slice. If it doesn’t find one there, it follows the prototype reference, and checks Array for that method, where it does find the slice method.
If you asked for something that doesn’t exist, such as tempArray.foobar(), tempArray, Array, and Object are all checked for the foobar method, and when it cannot find it you’re told that it’s undefined.