4 ms·
In my experience, closures are a topic that always comes up. It is also important to know how to handle a closure inside of a for loop. I've been asked about "t
by valeriemettler 10y ago
In my experience, closures are a topic that always comes up. It is also important to know how to handle a closure inside of a for loop. I've been asked about "this" binding, coercion, and CSS specificity. I've had to solve problems that required me to know about how to use stacks, trees, and nested for loops. Other topics that have come up are how to architect an app, concurrency, memoization, building out and handling api endpoints, and pass by reference vs. pass by value.
You may not think databases are a front-end topic, but I have been asked about them on more than one occasion. Prepare to talk about sharding, natural primary keys, what your favorite database is and why, etc.
Something that has been extremely useful for me is to have a project that I've built myself to show and talk about during the interview. Although I have had one interview where I was asked to talk in detail about how I built some of my projects that are in my github, I like to respond to general technical questions while referencing something I've built. A lot of times the interviewer will then use my app as a starting point into a discussion for how I would scale it. Here's an example of an app I built quickly and have used for discussion in interviews: http://moviemap.xyz/ http://moviemap.xyz/ More here: http://valeriemettler.com/ http://valeriemettler.com/
- mathgeek 10y ago> In my experience, closures are a topic that always comes up. Opinions will differ, but IMHO closure is a great concept to divide those who know JS at a conceptual level (or at least have crammed for the interview) from those who don't.
- ShellfishMeme 10y agoI agree. We always put the little 'for loop that creates a list of functions that spit out the current number of the iteration' exercise first in all of our interviews. Generally, when people solved that one fast, they also did well in the rest of the interview and if they struggled there, they also had a hard time coming up with an elegant solution for most of the other tasks. What I also like about it is that a closure isn't the only way to solve it. You can use `let` for example to make sure the variables are block scoped, or use `bind` to partially apply a function with the number. So in the end it's a conceptually very simple exercise that can give you a very good insight into how much the candidate knows about how JS actually works.
- danyim 10y agoWould that exercise be the following? I'm not sure I understand what's being tested. const f = (k) => { const funcs = []; for(let i = 0; i < k; i++) { funcs.push(() => i); } return funcs; } const test = f(4); console.log(test[0]()); // 0 console.log(test[1]()); // 1 console.log(test[2]()); // 2 console.log(test[3]()); // 3
- ricardobeat 10y agoTry writing that same thing without ES6.
- danyim 10y agoI'm also in the process of interviewing for a front-end engineer position, so thank you for replying and providing feedback. I'm assuming it has to be written this way because the function being pushed was referencing i, which was within the scope of the closure. Turning it into an IIFE breaks out of that. Thoughts? // Assuming pre-ES6 function iterate(k) { var funcs = []; for(var i = 0; i < k; i++) { (function(num) { funcs.push(function() { return num; }); })(i); } return funcs; } var itTest = iterate(4); console.log(itTest[0]()); // 0 console.log(itTest[1]()); // 1 console.log(itTest[2]()); // 2 console.log(itTest[3]()); // 3
- mathgeek 10y agoI'd probably ask you to do the printouts from within the function itself. If you haven't already read them, I highly recommend the You Don't Know JS series of books. One of them covers this exact question.
- weaksauce 10y agoneat series of books. thanks for the tip https://github.com/getify/You-Dont-Know-JS https://github.com/getify/You-Dont-Know-JS