Live data from Hacker News

Ask HN: “Expert Level” JavaScript questions?

news.ycombinator.com

11–20 of 54 posts

Re: Ask HN: “Expert Level” JavaScript questions?

#11
post #8

A good interviewer will start at a high level and drill down into what you're experienced with, rather than pick an obscure topic and assume you've done your homework. For example, they might ask for a hard problem you've recently solved in your last company. If you say something related to code splitting, you can expect he'll drill down more specifically into webpack, dependency cycles, etc. If you say something rel…

By this metric, extremely few interviewers are good, and candidates should assume an interviewer won’t be good and instead do the esoterica homework & trivia memorization, as there won’t be economic returns to one’s interview effort otherwise.

If I had known this as a high school student, I never would have studied math and computer science. Easily one of the most anti-inclusivity and self-defeating aspects of tech.

Re: Ask HN: “Expert Level” JavaScript questions?

#13

Senior level JavaScript I would imagine it to be entirely about frameworks and ES6 shims a.k.a. things you don't actually need. I recommend using as many buzz words as possible.

> ES6 shims a.k.a. things you don't actually need

Though it sounds a bit jaded— can confirm. I've been asked to re-implement `bind` before.

I gave it a shot but ultimately shrugged and explained that I'd rarely ever extend a native object and would rather use a community-supported polyfill. Nevermind that in my current field we haven't had to support ES3-capable browsers for ages.

I'd certainly be better off knowing, but rarely would I need to know on the spot. There is more beneficial knowledge to have up front.

Re: Ask HN: “Expert Level” JavaScript questions?

#14

Explain why ['1','1','1'].map(parseInt) returns [1, NaN, 1] but ['1','1','1'].map(n => parseInt(n)) returns [1, 1, 1].

Thanks for the chuckle.

To save everyone from having to look this up on Stack Overflow:

.map passes two arguments to the function it calls - the value and the index. The parseInt function takes up to two arguments, a string and a radix.

So there’s nothing broken here about .map, you just aren’t expecting the second optional argument for parseInt.

So the actual equivalents are: ['1','1','1'].map(parseInt)

And

['1','1','1'].map((n, index) => parseInt(n, index))

Re: Ask HN: “Expert Level” JavaScript questions?

#15

Explain why ['1','1','1'].map(parseInt) returns [1, NaN, 1] but ['1','1','1'].map(n => parseInt(n)) returns [1, 1, 1].

What the hell, who on earth thought that behaviour would be a good idea?

.map(fn) calls its callback with three arguments, the value, the index, and the full array. Then parseInt takes two arguments, the string and the base (radix).

"1" of base 0 is 1

"1" of base 1 is NaN

"1" of base 2 is 1

The gotcha here is if you map(fn), you're going to get all three arguments sent to the fn, where map(v => fn(v)) explicitly only sends the first one.

Re: Ask HN: “Expert Level” JavaScript questions?

#16

Explain why ['1','1','1'].map(parseInt) returns [1, NaN, 1] but ['1','1','1'].map(n => parseInt(n)) returns [1, 1, 1].

What the hell, who on earth thought that behaviour would be a good idea?

Nobody thought about it or did that on purpose to confuse you with this particular example. If you would do js enough you still could be surprised at first but then you'll see it's pretty valid behavior. map will pass value and key to the method given. so it will call parseInt('1', 0) parseInt('1', 1) parseInt('1', 2)

Re: Ask HN: “Expert Level” JavaScript questions?

#17
Senior roles require that you can break down large problems into digestible chunks. "gotcha" questions don't tell an interviewer how good you are architecting, or how well you understand the language. "gotchas" are usually easily Google-able too.

I've asked a lot of code structure questions. JS really easily turns into spaghetti code if a dev isn't careful. I like to test candidates on whether they make code understandable with clean closures, modules, files, etc. I'll also ask about which libraries they used, why they used them, and what they liked/disliked about the library. Also, "because that's what the code base was in, and there was no reason to change it" is a legitimate 'why'.

For language specific things: - How closures, scopes, and prototypal inheritance work is important. This is often tested with nested callbacks. - Web API design - HTTP methods (Not as important if a candidate's background is in RCP, GraphQL, or something that doesn't use HTTP methods RESTfully)

Re: Ask HN: “Expert Level” JavaScript questions?

#18

trickiest/deepest questions ive ever gotten are: variable hoisting how to extend a class/prototype es6 features typescript/flow tdd tooling/webpack

Nothing about context? Sad. You can find many tricky questions and all of them would be about context.

Re: Ask HN: “Expert Level” JavaScript questions?

#20

Explain why ['1','1','1'].map(parseInt) returns [1, NaN, 1] but ['1','1','1'].map(n => parseInt(n)) returns [1, 1, 1].

What the hell, who on earth thought that behaviour would be a good idea?

No one ever thought it would be a good idea, Contravariant. :/ It's just an unfortunate interaction between two APIs. Map's callback gets three args, and parseInt takes two (and ignores the third). After a while, you get used to wrapping callbacks to slough off the spare variables as shown.

In this case, the index of the element (1, 2, 3) is getting passed as the radix with which to parse the element (1, 1, 1).

Post reply on HN