|Written by Nikos Vaggalis|
|Monday, 16 March 2020|
Array Sort Comparison
Consider the following arrays. What gets logged in various sorting conditions?
The question is followed by multiple choice answers:
true true true
After you make your choice, be it right or wrong, an explanation is provided :
There are a couple concepts at play here. First, the array sort method sorts your original array and also returns a reference to that array. This means that when you write arr2.sort(), the arr2 array object is sorted.
It turns out, however, the sort order of the array doesn't matter when you're comparing objects. Since arr1.sort() and arr1 point to the same object in memory, the first equality test returns true. This holds true for the second comparison as well: arr2.sort() and arr2 point to the same object in memory.
In the third test, the sort order of arr1.sort() and arr2.sort() are the same; however, they still point to different objects in memory. Therefore, the third test evaluates to false.
In this question, we have a Dog constructor function. Our dog obviously knows the speak command. What gets logged in the following example when we ask Pogo to speak?
Every time we create a new Dog instance, we set the speak property to that instance to be a function returning the string woof. Since this is being set every time we create a new Dog instance, we never use the prototypal speak property on Dog that returns the arf string.
Others quizzes include :
and so on.
As the list indicates, the quiz is addressed to the intricacies of the language and spans important and tricky concepts that you need firmly established foundation of in order to progress further with the language. Nick Scialli does warn however:
I'm considered a senior developer and would probably have trouble with a lot of these questions had I not made them myself. Please don't be hard on yourself as you attempt these questions; we're all still learning!
Scialla also offers the quiz as a self hosted option so that you can adapt it to a local network (i.e corporate environment) or even make your own for educational purposes, simply by cloning its Gitgub repo.
|Last Updated ( Monday, 16 March 2020 )|