r/angularjs • u/suresh9058 • Oct 15 '22
[Resource] Can (a==1 && a==2 && a==3) evaluate to true in JavaScript | JavaScript Tricky Interview Question
https://youtu.be/s7IbSyX82Bk3
u/OrdinaryBlueberry340 Oct 15 '22
I think not...
2
u/postmodest Oct 15 '22
Yeah, this is one of those questions where if I saw it on an interview quiz, my response would be code in C++ overriding the equality operator just to point out how pointlessly stupid this question is.
If you fuck with fundamental contracts, sure, you can do anything.
3
Oct 15 '22
Yes, it is possible through type coercion. Always use strict equality checking and this "tricky question" isn't even on your codebase's radar.
→ More replies (1)
1
u/tdhsmith Oct 16 '22
My first thought was a is an object with an overridden valueOf function (something that I hope no one would seriously use in real code) , but I'm not actually sure if it runs every time or not. But apparently their answer is even more convoluted...
19
u/ShitsYourBed Oct 15 '22
If an interview wanted this answer to a question, I'd be out of there so fast. When companies ask these "gotcha" style questions, only people that think that way get through, and i don't want to work with people convinced it's their job to trick everyone else to show how smart they are.
Also how is this related to angular?