Earlier quoted context omitted.
That's using a closure, another would be to use Function.prototype.bind (but really that's still using a closure, just putting it out of sight), can't think of any others.
>Function.prototype.bind (but really that's still using a closure, just putting it out of sight), How is `bind` still using a closure? `bind` just allows users to alter a function's execution context. However, the implementation varies according to the JS engine. Some of them may use a closure internally as a part of the process, but I don't think V8 does.
Front End Developer – Interview Questions
91–100 of 152 posts
Re: Front End Developer – Interview Questions
#92This looks like a giant list of trivia that has almost no bearing on the day-to-day effectiveness of the candidate. For example, I don't have the slightest clue what the answer is to probably half of these and a lot of my job is to write javascript that gets run millions to billions of times a day. The "code questions", by contrast, were all ridiculously easy. So, would it really matter if you are hiring someone who…
Simply getting the names mixed up and needing to look them up is one thing, but if the unfamiliarity stems from a general unfamiliarity with those methods and their respective use cases, then it would be a red flag for a "senior dev" sort of position.
Re: Front End Developer – Interview Questions
#93I really like this js question (whiteboarding): Implement function foo which takes an integer size, and returns an array of that size where each element in that array is a function that returns the index of that function in the array. Testcase: 42 === foo(1000)[42]() There are 3 different correct solutions. Discuss which solution is better, worse... etc (if they get there) (could probably be worded better, I'm not an…
var foo = function (arr, i) {
if (typeof arr === 'number') {
arr = new Array(arr);
foo(arr, arr.length - 1);
return arr;
}
if (i === -1) {
return;
}
arr[i] = function () {
return i;
}
foo(arr, i - 1);
};Re: Front End Developer – Interview Questions
#94This looks like a giant list of trivia that has almost no bearing on the day-to-day effectiveness of the candidate. For example, I don't have the slightest clue what the answer is to probably half of these and a lot of my job is to write javascript that gets run millions to billions of times a day. The "code questions", by contrast, were all ridiculously easy. So, would it really matter if you are hiring someone who…
I was thinking the same thing. I've built manys a website in pretty much every front-end language imaginable and I would struggle to answer many of these. Yet I feel little shame in saying that I believe myself to be a very competent programmer. What is the significance of having memorized a bunch of arbitrary terms? If you don't know what the difference is between and that doesn't mean you aren't a competent develop…
No, but it does mean that you don't know about deferred script execution and possibly do not have a lot of experience in optimising page performance.
Hardly the end of the world, but if you're looking for a senior developer you might really want that skillset.
Re: Front End Developer – Interview Questions
#95Earlier quoted context omitted.
How often do you use call and apply? I've been a JS developer for a long time, have written a lot of JS code, and rarely need to use call and apply. Unless you're writing all your code from scratch and not using any frameworks / util libs (which you should) you won't need them very often.
Fairly often. Since the selected DOM element is the value of this in any event handler callback, you can migrate out the function and use it for different things (i.e. validation of, say, autofill after a settimeout) and different contexts with call/apply.
Re: Front End Developer – Interview Questions
#96Re: Front End Developer – Interview Questions
#97This looks like a giant list of trivia that has almost no bearing on the day-to-day effectiveness of the candidate. For example, I don't have the slightest clue what the answer is to probably half of these and a lot of my job is to write javascript that gets run millions to billions of times a day. The "code questions", by contrast, were all ridiculously easy. So, would it really matter if you are hiring someone who…
> doesn't remember the difference between .call and .apply Simply getting the names mixed up and needing to look them up is one thing, but if the unfamiliarity stems from a general unfamiliarity with those methods and their respective use cases, then it would be a red flag for a "senior dev" sort of position.
f.apply(this, arrayOfArgs); // Array
f.call(this, arg1, arg2, arg3); // ColumnsRe: Front End Developer – Interview Questions
#98I really like this js question (whiteboarding): Implement function foo which takes an integer size, and returns an array of that size where each element in that array is a function that returns the index of that function in the array. Testcase: 42 === foo(1000)[42]() There are 3 different correct solutions. Discuss which solution is better, worse... etc (if they get there) (could probably be worded better, I'm not an…
function foo(count) {
var ret = []
for (var i=0; i Re: Front End Developer – Interview Questions
#99Earlier quoted context omitted.
> doesn't remember the difference between .call and .apply Simply getting the names mixed up and needing to look them up is one thing, but if the unfamiliarity stems from a general unfamiliarity with those methods and their respective use cases, then it would be a red flag for a "senior dev" sort of position.
I like to associate `.apply` with "Array", and `.call` with "Columns". f.apply(this, arrayOfArgs); // Array f.call(this, arg1, arg2, arg3); // Columns
:)
Re: Front End Developer – Interview Questions
#100I really like this js question (whiteboarding): Implement function foo which takes an integer size, and returns an array of that size where each element in that array is a function that returns the index of that function in the array. Testcase: 42 === foo(1000)[42]() There are 3 different correct solutions. Discuss which solution is better, worse... etc (if they get there) (could probably be worded better, I'm not an…
It's a good question, and a pretty fair one for a Javascript developer to know, given the role that closures play in the language. That said, I'm not thinking of a 3rd solution. Closures(best?), a global(worse), what else? Edit: As Daiz points out, the bind I was thinking of doesn't even have to even be to a global. But we still have seen only two solutions: variations of binding and closures. What's the third? Inqui…
- bind
- function creator outside of the loop called from within
- create an anon function on each loop iteration that acts like the function creator in #2
The bind is best in terms of memory and simplicity, but will not run on on IE 8 or crappier, so in that case #2 is preferred.The last one creates anon functions needlessly, but is very compact to write.