6 ms·
We were hiring a non-senior full-stack developer recently and I noticed there were no "frontend" questions on the list, so I added what I thought would be a que
by steven777400 13y ago
We were hiring a non-senior full-stack developer recently and I noticed there were no "frontend" questions on the list, so I added what I thought would be a question that any developer with frontend experience could answer, and would also pave the way for some more interested discussions for an advanced candidate. The question was something to the effect of "In JavaScript, what is the value of 'this' in a method?"
I would have accepted an answer as simple as "The value of 'this' depends on how the method is called" or even "The value of 'this' confuses me because it's often not what I expect."
It was a disaster. We may as well not have asked the question at all. Nobody seemed to even be aware of anything about it.
- matwood 13y agoI don't even write JS much and I know 'this' is a trap question.
- byroot 13y agoIt's not a trap. It's just required knowledge. Saying you're a Javascript developer without understanding the behaviour of `this`, is like saying you're a C developer without understanding what a pointer is.
- byroot 13y agoI always include something around `this` behaviour in my interviews if the position is Javascript related. You cannot possibly have a decent experience in JS without have been bit by this. And I'm always amazed by the amount of developers that just do not understand how it works, and bind every possible methods.
- ac2u 13y agoLikewise, I ask it also. When someone has spent the last 3 years as a "JavaScript developer" and doesn't have a basic grasp of context in JS, them it's a red flag.
- badman_ting 13y agoAnyone who claims to know JS and doesn't have "this" down cold is either a disaster waiting to happen, or a disaster in progress.
- benched 13y agoNow, hold on there. These "anyone who" statements chafe me; like the junior dev who exclaimed "anyone who doesn't write unit tests shouldn't call themselves an engineer" in a meeting filled with people 15 years his senior who had collectively shipped far, far more successful software than him, without writing tests. Several years ago, I led two different front-end web teams at a large, well-known company. I wrote a lot of JavaScript then. In fact, I wrote the core JS framework for one of the apps. I probably understood "this" at that time. I couldn't begin to tell you now, because I've been working on hit iOS games since - probably without knowing a lot of the nuances of Obj-C at times! There was no disaster back then - we shipped high-quality sites on time. There would be no disaster now, because if I went back to JS I'd crack a book. The most important skills I bring to any project are a lot higher-level than the details of a particular language. I haven't made my career on one language or platform, but dozens of them. For the details, I work with reference material handy. After a month, I probably have a good grasp of whatever I'm working with. A year after that project, I probably don't, but I could bring it back easily.
- badman_ting 13y agoThat's cool. But don't write JS if you don't know what this does, because it will bite you.
- xdfgsd 13y agoYou JS cretins are the worst. I never ceases to amaze me how seriously you take syntax bikeshedding and browser quirks over the big picture. No other community even comes close to the pedantry and nitpicking I've observed among most JavaScript developers.
- Bahamut 13y agoOr just avoid using `this` unless you're sure about what it does in a particular context.
- vikas5678 13y agoYes, interviewing developers for front-end positions has been a nightmare for me too. I interviewed about 40 developers to fill 3 new positions. Yikes. "This is how its done in JQuery" is not a acceptable answer! I expect atleast some basic knowledge of DOM manipulation without using a library.
- scrabble 13y agoI wonder how many front-end people out there currently believe that JavaScript is jQuery and don't have a solid grasp of the language, instead focusing on use of a single library.
- pedalpete 13y agoFrom my interviews over the last few months, apparently it is a large number of developers. I've had interviewers check that when I say javascript I don't mean jQuery.
- sbank 13y agoFrom the top of my head, from someone who currently seeks work as a full stack (Rails) developer: I would ask if you by "method" mean function defined on an object. If so, this refers to the method's object. If not, this can take on 5 values. In the global scope it is the global object; in a constructor it is the newly created object; in a function (not defined on an object - and also goes for functions defined within methods defined on objects) it is the global object; in a method (defined on object) it is the object, and finally it can be set explicitly with functions like call and apply. How did I do? (Serious question. I think my answer is good, but I also struggle with a serious form of imposter syndrome.)
- steven777400 13y agoI did mean "function defined on an object". Your answer would have been way ahead of everyone else because no one else had an answer. :) I would also add, though, that function definition is not the critical aspect to define this. The value of this primarily varies based on how the function is called, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- davedx 13y agoNot quite right. :-) JavaScript is not truly OO. You can have a prototype method called from a callback and find that 'this' will not necessarily be the value of the object it was prototyped onto. It's really tricky, and I often have to .bind functions after I've noticed they're not working.
- nicholas73 13y agoI'm curious, should answering this question be expected of a non-senior dev? This kind of knowledge is acquired by running into broken code - that is, by chance. I'd think someone with a couple years experience only could conceivably not, for example, have called a method directly and had this refer to a global object instead. Until then one might just assume Javascript's this works like this in other languages. In fact, that's what I did until your post just made me look it up (though I only code for side projects, not professionally). I'm also surprised to hear that people learn jQuery and omit Javascript. Personally I resisted using jQuery because I didn't understand what was happening nor would you read the code easily. Plus, it was actually extra work because if you knew another language you could pick up Javascript easily. With only jQuery you are pretty much limited to what's already made for you. If anyone wants to look at one of my sites, I'd be curious how I stand as a developer. http://www.sudokuisland.com/ http://www.sudokuisland.com/
- dustingetz 13y ago!!!! This kind of knowledge is acquired by reading 'Javascript the Good Parts'. It goes without saying that someone who considers themselves a good frontend engineer has read this book. edit: I am a frontend tech lead (not even in SV!!) and my most junior engineer will answer the question correctly. I can't even fathom how one could contribute to a non-toy app without knowing this.
- nicholas73 13y agoPeople tend to remember things that they do, not what they read, much less from what they hear in lecture. The odds that I'm right is high because nobody was able to answer the question satisfactorily.
- spencewah 13y agoI had to do a short javascript project at work and the differences between the various function invocations was one of the first things I learned. That and how to deal with the disastrous scoping issues.
- teleclimber 13y agoTo the people who wish they could answer that question with confidence, I recommend getting this book: http://www.amazon.com/Effective-JavaScript-Specific-Software-Development/dp/0321812182 http://www.amazon.com/Effective-JavaScript-Specific-Software... Just got it and I feel like it clarified so many things about Javascript that I didn't have down cold as a self-taught pragmatist.
- platz 13y agoI felt Effective Javascript was pretty on par with The Good Parts, and even better in some aspects.
- drgath 13y agoI concur. I recently finished Effective JavaScript, and found it to be an excellent and insightful read.
- ulisesrmzroche 13y agoI'll 4th this recommendation thread for those still on the fence. This and also Secrets of the Javascript Ninja.
- kika 13y agoI hate HN. Instead of watching action flicks on flights I now read books picked up from HN threads. I've got Platinum Medallion this year and I'm still behind my reading queue.
- __derek__ 13y agoAgreed. I cannot recommend that book enough. It's a natural extension of The Good Parts and should be considered required reading (in the same way that Effective Java is for Java developers).
- wturner 13y agoI've been doing Javascript for a few years and recently answered a few StackOverflow questions. One was regarding "this".If anyone wants to hire my ass feel free to contact me. One of my techniques for learning has been by going on interviews and flopping, then going back and learning all the interview question material on my own time. Wash and repeat.I've been doing this bullshit since the first day I started teaching myself. It all began with an interview that required knowledge of strictly HTML & CSS. Suffice to say after I tried to mimic an unordered list with 12 div blocks I didn't get the gig. Things are better now. I promise! Where am I? Whats this padded wall doing here? !!!!
- deleted 13y ago[deleted]
- lemonberry 13y agoThis is a great, great idea. Thank you for the tip.
- wturner 13y agoIt only works if you have a shit ton of humility. The problem is there is really no other way I've found to acclimate oneself with the assumptions and culture of the discipline in a manner that is real-world and cuts through the small talk/cruft . Your welcome btw...have fun :/
- steven777400 13y agoIf you're looking, we are still hiring for a third position (we've been on a bit of a binge lately with hiring). http://agency.governmentjobs.com/washington/default.cfm?action=viewJob&jobID=775637 http://agency.governmentjobs.com/washington/default.cfm?acti...
- wturner 13y agoThanks. I'll fill it all out in the next 24 hours
- 13y ago
- sp4rki 13y agoI've been in this position also. Same question. I also added what the difference between setTimeout() and setInterval() is, and example usages of both. It's incredible that a question where the primary answer is right there in the function names causes such confusion on people that are supposedly "front end engineers with years of experience". Off course, disaster is an understatement. All three questions where the demise of 100% of our interviewees. We ended up hiring a sql programmer and teaching him what he needed to know.
- fibbery 13y agoHeh. The second question makes me feel a lot better about my JS knowledge. I could probably answer what 'this' is when given some code (eg are we inside a class? or a jquery event handler?) but would be hard pressed to discuss it in the abstract... whereas setTimeout and setInterval have specific differences to point to.
- BSousa 13y agoCan I ask where (location) was this? I have trouble understanding how someone would call himself a JS developer and not knowing it. I'm not at all a JS developer (even though lately I've been knees deep in nodeJS code) and most of my experience is away from the browser, but even I knew this. I was responsible for hiring at a previous company and I did see some people passing as Senior SQL developers without knowing how to do a join correctly, but I always passed it as a local thing (culture here is as long as you graduated you don't need to learn anything new) but not in other more competitive places.
- steven777400 13y agoA state government agency about 2 hours south of Seattle, WA. What happens is that Microsoft, Amazon, etc can offer 50 to 100 percent higher salaries and more interesting problems than we can, so most of the really skilled devs go there (I don't blame them). So out pickings are almost always slim.
- adamb_ 13y agoFor those curious, here's a great summary of key JS concepts to know: http://stackoverflow.com/a/2629004/1538708 http://stackoverflow.com/a/2629004/1538708
- driverdan 13y ago> It was a disaster. We may as well not have asked the question at all. Nobody seemed to even be aware of anything about it. You have it backwards. It would have been a disaster if you didn't ask the question and hired someone who doesn't know basic JS fundamentals.
- __derek__ 13y agoOn the one hand, that makes me want to decry the state of the world and of our profession. On the other, it's kind of heartening to know that that's the state of the competition (so to speak) when I want to change jobs.
- barrkel 13y agoYou can get by without knowing how 'this' works, if you use CoffeeScript and change -> to => when @ doesn't work the way you thought it would the first time :)