Hacker News new | ask | show | jobs
by lostcolony 4311 days ago
That kind of question can actually be useful as a proxy for experience with the language, and whether you're the type of person who digs into understanding your tools. If you say "I'm a rockstar Javascript dev", it's very hard to prove it; but if you've never been bitten by some of Javascript's type conversions, and/or have never really looked into some of its intricacies on your own, you probably aren't. It's just one data point, it won't be enough on its own to sway the interview either way, but it's interesting.

To give you an idea, I once interviewed a Javascript dev who said you should null out your variables with 'undefined' when you were finished with them. Oh, why is that? 'Because sometimes they leak out into the global scope and that can cause problems elsewhere in the code.' This person had noted that you could declare a global anywhere in Javascript, but had not noticed, nor asked anyone, nor looked up, nor anything, to find out that there's a difference between "x = 5" and "var x = 5". We didn't hire him.

Had he simply been unaware you -could- declare globals (and had instead said that "x = 5" won't work, you have to use the 'var' key word, or something), we wouldn't have counted it against him; he's following a best practice and never encountered it, fair enough. If he had never been bitten by the scoping rules, fair enough, a minor ding but we'd continue the interview. But the fact he had seen it, possibly been bitten by it, and just handwaved it away as non-deterministic weirdness that required a mystical incantation to avoid? No.

1 comments

I find it hard to believe anyone has spent a bunch of time writing js and never been bitten by a type conversion. Am I wildly off base?

I do data science, but everyone who writes R has been bitten by it's scoping rules, which are definitely not mainstream. Everyone I know who writes java or python has been bitten at least once by the pass object references by value (is there a better name for this?) function argument semantics. Everyone who writes java has accidentally written == when they meant .equals and stared at the code for far too long. etc etc etc You just can't claim you can competently use a language without understanding some basics, like how functions work, how arguments are passed, and how equality is decided.

Not at all off base.

Which is the reason I would be deeply annoyed by the 4 == '4' question. The technical answer is it evaluates to true, but the real answer is "any code that requires all readers to have intimate knowledge of Javascript type conversion rules to read and understand is horrific code."

I'm with @lostcolony: if I were interviewing and a candidate said "don't do that, it's unpredictable, do this instead" it's a great answer.
At the same time though, as someone looking for their first dev job, I'm not going to tell the interviewer "don't do that." Given the people I've met in industry, I can't see that ending well- I would expect some variation of "who does this kid think he is!?"
True, but one time I was asked about the difference between "foo = bar" and "var foo = bar", and my answer was, "Don't do the first."
You can always phrase it as, "That's ill advised, here's why, my guess is it does X, but you probably shouldn't do that in production code".
pass object references by value (is their a better name for this?)

Barbara Liskov used "call by sharing", aka "call by object-sharing" or "call by object". http://stackoverflow.com/questions/40480/is-java-pass-by-ref...

thank you! I really like that
Agreed. So when someone answers it wrong, while claiming some knowledge of Javascript, that's kind of a major ding against them.