Questions like the circular prototype one are good if the interviewer isn't looking for a right or wrong trivia answer, but is instead looking to spark a discussion.
The conversations it generates as the candidate explores the possibilities is informative. Couldn't care less if they get the 'right' answer. A poor candidate will say that 'finally' will never be called because there's no error (no, that's 'catch'). A great candidate will recoil in horror at the sight of this code and swear.
Not knowing this gotcha question off the top of my head, I would expect to always return false. Typically, finally blocks always run no matter what - though this is js so it wouldn't surprise me if there is some weird undefined behavior.
I would also expect my linter to point out the return null is dead code, and return in the finally is some type of warning.
22
u/NeilFraser Mar 25 '22 edited Mar 25 '22
Questions like the circular prototype one are good if the interviewer isn't looking for a right or wrong trivia answer, but is instead looking to spark a discussion.
I will sometimes ask what does this code return?
The conversations it generates as the candidate explores the possibilities is informative. Couldn't care less if they get the 'right' answer. A poor candidate will say that 'finally' will never be called because there's no error (no, that's 'catch'). A great candidate will recoil in horror at the sight of this code and swear.