Hacker News new | ask | show | jobs
by eric_h 4209 days ago
I've used this gist: https://gist.github.com/erichummel/2595398 a few times in interviews to see just how much of a javascript whiz candidates were.

The basic gist of the interview question is "what is output to the console when this code is run?"

It's obviously intentionally obfuscated, so even if the candidate got it wrong (most did), subsequently talking through the solution told me a lot about how good a candidate was at static analysis and talking through a problem.

1 comments

Does `setTimeout` have a default value for the time?
setTimeout with no timeout argument simply schedules the provided function for when the interpreter is next idle. Underscore.js wraps a similar unqualified call in _.defer (last i checked, anyway; they might now provide it with a very small number or 0 for the timeout).

Edit: in both cases the result is the same in most browsers.

It's clamped to 4. You can't go lower than that.

There is `setImmediate` for making something run the very next cycle. However, only IE10+ supports it and the other browser vendors are against it. You can use abuse `postMessage` to get a similar effect.