Hacker News new | ask | show | jobs
by nicholas73 4567 days ago
I'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/

2 comments

!!!!

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.

People 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.
I 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.
This kind of knowledge is super basic, so yes, I'd expect anyone interviewing for a front-end position to know the meaning of 'this.'
The answer the interviewer was looking for seems to expect knowledge of how 'this' is different in Javascript versus other languages, and how things can go wrong. That is different from simply knowing that 'this' refers to an object.

Since this is for a junior position, conceivably an applicant could be a recent CS grad with no formal JS training, and hacked some projects on a side or job. And thus never by happenstance run into this issue, even if he read it somewhere sometime.

As someone that is self-taught via books, websites and finding stuff out on Stackoverflow, etc. I feel like everyone should know this. I hear all languages have their quirks, but this is emphasized so much in JS that if you don't have at least a passing familiarity with it I'd wonder how learned the language. However, most people are way smarter than me and maybe they're learning through reading code and just building. In this case, sure, maybe they've never run into the issue.
To be clearer, I wasn't just referring to the fact that 'this' refers to an object, but the complexity inherent in the term in JS.

You can run into this problem by doing something as basic as using it in a click handler if you don't know that it's there.