5 ms·
I've reduced my JS interview test to just one question: "What examples of falsy values can you name?". Anyone working with the language will be inevitably regu
by Tade0 3y ago
I've reduced my JS interview test to just one question: "What examples of falsy values can you name?".
Anyone working with the language will be inevitably regularly reminded which these are.
The least mentioned is NaN followed up by... false. But I can't blame anyone for forgetting that one, as it's too obvious.
- mvdtnz 3y agoThat's one of the worst interview questions I have ever heard.
- intothemild 3y agoIf its just the one question then sure i agree... but if it was used as a kind of fun icebreaker question, then I can kind of see where it could be used. But it's just very much asking around https://javascriptwtf.com/ https://javascriptwtf.com/ level stuff
- Tade0 3y agoCan't agree here. Especially when you deal with unsanitized data - like from a 3rd party API - you're bound to eventually have each of those cases find their way into your if statements/expressions. Also, this question works for other languages too, as e.g. NaN can evaluate to True (Python) or have an undefined behaviour but still evaluate to true (C, C++) - it's useful to know what is true and what is false(y) in your language of choice, especially coming from another language.
- Tade0 3y agoThank you for your opinion - it's proven reliable over the last decade.
- rvba 3y agoSince I didnt think such word even exists I googled and apparently there is something called "falsy" in javascript. To make it worse, there is a "truthy" too. I guess a technical question. But my eyes.
- Drakim 3y agonull, undefined, NaN, false, 0, '' How did I do?
- noman-land 3y agoDon't forget -0.
- pcthrowaway 3y agoThat's just another name for 0
- WorldMaker 3y agoBut a different representation in IEEE 754 floating point. If you were building a JS interpreter it would be important to catch that 0 and -0 are different numbers in memory and to hardware operations.
- noman-land 3y agoMDN specifically calls it out. https://developer.mozilla.org/en-US/docs/Glossary/Falsy https://developer.mozilla.org/en-US/docs/Glossary/Falsy
- Drakim 3y ago0 === -0
- noman-land 3y agoMDN specifically calls it out. https://developer.mozilla.org/en-US/docs/Glossary/Falsy https://developer.mozilla.org/en-US/docs/Glossary/Falsy
- Drakim 3y agoHold on the real nugget here is that apparently document.all is a falsy object. Why in the world would that be the case?!?