The following questions are intended to be challenging and instructive. If you know exactly how to answer each one, that's great, but if you get so...
For further actions, you may consider blocking this person and/or reporting abuse
Just noting that === is not an identity operator -- it's the strict equality comparison operator.
We can easily tell that it is not an identity operator because, e.g., NaN === NaN is false.
It's a bit problematic to say this, since Javascript doesn't have pointers.
It's sufficient to say that a and b have the same value, so they are the same object, and so provide access to the same properties. The rest then follows as you've said.
the equality operator (==) will attempt to make the data types the same before proceeding
the identity operator (===) requires both data types to be the same, as a prerequisite.
We can tell that === is not an identity operator since it may return false when comparing a value with itself.
e.g. NaN === NaN.
NaN === NaN // false,
The identity evaluation algorithm (IEA) rule 4
Operands are the same type (numbers), but the IEA rule 4 indicates than nothing is equal with a NaN.
The result is false.
Also,
NaN
s are the only non-reflexive value, i.e.,if x !== x, then x is a NaN
more details:
dmitripavlutin.com/the-legend-of-j...
The page you've referenced is mostly correct, but they're a bit confused on terminology, and have made things rather more complicated that necessary.
See: ecma-international.org/publication...
Now, what this means is that some things with the same identity compare false with ===, and some things with different identities compare true with ===.
e.g.
NaN === NaN is false
-0 === 0 is true
Which means that it is not checking the identity of the operands -- it is computing a kind of equality (using the strict equality comparison).
So, === is not an identity operator, and for these reasons is not called an identity operator in the language specification.
It's just some confused people on the internet who are making that into a popular mistake. :)
Some instructive feedback for question 10: initialize greatest to
-Infinity
(orarr[0]
)These are very nice questions that probe JavaScript fundamentals and not ephemeral trivia. I suggest you change #4 and #6 so that they don't require knowledge about the behavior of == vs. ===. (Nobody should use == with JavaScript in 2020.) If you think that makes #4 too easy, perhaps you could add whether
Object.keys(obj).map(x => parseInt(x)) === Object.values(obj)
. And as a bonus puzzler, why isn'tObject.keys(obj).map(parseInt)
the same asObject.keys(obj).map(x => parseInt(x))
?Love the bonus question! That's quite the trap.
Very cool I love these. I am going to try the quiz in the link =)
Nice quiz. I enjoyed it more than other JS quizzes I have seen.
In Question 2 though, since it is about performance, it might be useful to know that a
var
declaration in afor
loop is more performant than alet
declaration. As long as yourfor
loop is scoped to a function, you should not get any nasty surprises.An example could be:
Here are 156 others:
github.com/lydiahallie/javascript-...
I'm learning Javascript, I have bookmarked this post.
I would like to come here later and check how many I can answer.
Thank you for this post
Don't forget to check these articles:
dev.to/macmacky/70-javascript-inte...
github.com/lydiahallie/javascript-...
Hey Nick ! I really liked the blog and wanted to tell you that as of now(16th March 2023 22:02 IST) my Like made your existing likes sum up to 200 . Than u so much for your work . Kindly keep Sharing your knowledge with us
Nice. Learnt many things. Thanks!
Cool post Nick, I've subscribed to your newsletter to getting some quality posts 🤟
Nice article. I like this kind of challenge because it helps me to keep my mind up to date with JS knowledge. ✨
That was fun. I got them all right. Great way to spend 5 mins post tea time.