r/javascript • • Aug 23 '17

10 JavaScript concepts you need to know for interviews

https://dev.to/arnavaggarwal/10-javascript-concepts-you-need-to-know-for-interviews
425 Upvotes

118 comments sorted by

72

u/crashspringfield Aug 23 '17

interviewer: Explain this. me: Can't I just use arrow functions?

55

u/zachwolf Aug 23 '17

"Thanks for coming in, we'all get back to you soon"

7

u/jahannan Aug 23 '17

Not if you're using classes! (extreme sad face)

6

u/senocular Aug 23 '17

Unless you make your methods instance members

7

u/Akkuma Aug 23 '17

If you make your methods instance members it should be for a good reason, as you're increasing memory usage and very likely reducing performance in comparison to strictly using it off the prototype.

1

u/SarahC Aug 24 '17

instance members .... Class.prototype.function = function(){} ?

1

u/YodaLoL Aug 24 '17

More like

x = new Class x.function = function () {}

1

u/SarahC Aug 28 '17

I've not seen that declaration type. Cool.

2

u/jahannan Aug 23 '17

Yeah that was poorly explained on my part, I was referring more to the ES6 class lack of closure support but good use of closures relies on understanding the this variable and you can't use them very well with arrow functions either.

Maybe one day they'll add the private keyword and we can finally forget about javascript's weird problems with this

12

u/senocular Aug 23 '17

Methods defined in class can be closures. Closures and context (this) are separate behaviors.

Class fields (stage 3) let you define members in the class body which can be arrow functions and they maintain a context of the class instance, just as if they were created in the constructor.

class Foo {
  bar = 'bar'
  getBar = () => this.bar
}

new Foo().getBar() //-> 'bar'

Private fields are also part of this, though they use a # identifier rather than the private keyword.

class Foo {
  #bar = 'bar'
  getBar = () => this.#bar
}

new Foo().getBar() //-> 'bar'
new Foo().#bar //-> Error

These are implemented similar to the weak map approaches used today. Of course that comes with its own problems, so it isn't a magic bullet for solving everyone's problems.

3

u/apatheorist Aug 23 '17

And that's when I walked out.

2

u/itsnotlupus beep boop Aug 24 '17

Last time this came up in here, someone clever suggested using a little custom decorator to bind methods you care about to the current instance.

Not that it saves much over something like _.bindAll(this, "methodA", "methodB"); in a constructor, but it's prettier.

1

u/christianflorez Aug 24 '17

If you're using babel, there are some experimental features that let you use arrow functions in classes.

15

u/dont_forget_canada Aug 23 '17

If that was your response then I would think you don't understand (or cant come up with) any scenarios where you may have to use this, and then I would think you're maybe too inexperienced for the job. I want you to understand prototypes, this, how you can change the value of this with .call, .apply, .bind, how you can use arrow functions to prevent the value of this changing when you pass a function to another function and then call it, etc. So if you just gloss over all this with "cant I just use arrow functions" then it seems like you don't know about any of this ^ and that's bad.

9

u/Asmor Aug 24 '17

There are certainly times where you can use this, and every JS developer should know if for no other reason than understanding and troubleshooting code they might encounter that they didn't write themselves...

But I think it's entirely reasonable for a moderately experienced front-end dev to have never been in a situation where they've had to use this. And, further, given two otherwise comparable solutions, I'd always recommend the one that didn't use this.

Hell, Douglas Crockford even has a project for making ad-safe JS that bans the use of this altogether.

2

u/FormerGameDev Aug 24 '17

I have been a professional Javascript user for right about 5 years now, and the only times I have ever used this is when it's required because something else i'm interfacing puts it's output into this. While this is technically predictable, if you're writing something that is intended to be used by other code that you don't have control over, you can't always know what this will be, without resorting to ugliness, and if you can't know what it's going to be, then you have to validate that it is what you expect it to be, and it's just a huge mess. Add on top of that, that since "bind" was so popular in old code to force "this" to something or other, then it becomes a real nightmare to reason about.

  • yes, i'm aware that this is somewhat simplified, and i'm aware that in the past people have made significant use of the this behavior.

4

u/anton_rich Aug 24 '17

Now, I'm actually as a novice quite surprised about the 'this' keyword. Because from what I understand there is a lot of emphasis in learning materials on understanding this concept and it turns out it's a dangerous concept overall. The question is how do I not use it? What are the best practices without 'this'?

6

u/RnRau Aug 24 '17

Just write functional code. I do react/redux in a functional manner, and in that code base I don't have to deal with 'this'. In my meteor code base, its unfortunately common.

Learn a little haskell, its a big language, but you don't need much to get a taste for how a purely functional language works. Then start playing with lodash, ramda, etc. Your code structure will tend to become simpler over time (modules, closures, functions is all you need) and 'this' is simply not needed. At least in your own code :)

5

u/benihana react, node Aug 24 '17

so i've been programming with JS for about 16 years and i'm not sure what homeboy above is on about, to be honest.

you're going to need to use this any time you write a complex object with any kind of functionality. if you have closures (for example anonymous callbacks or anonymous promise handlers) in those functions you'll probably need to rebind this from time to time in the anonymous functions as well. it's not scary or a nightmare, it's just a normal part of JS.

my advice is understand JavaScript scopes and JavaScript binding and work through those to get an intuitive understanding of how this works.

6

u/FormerGameDev Aug 24 '17

"this" is, effectively, an invisible function parameter, that you can not be 100% positive refers to any specific thing (what if someone calls your function with it bound to something totally unexpected?) therefore, IMO, it is not useful. I truly cannot recall the last time I used "this", only that in the modern Javascript era, I've often thought "i'm so glad I don't have to constantly figure out what the hell 'this' points to". Perhaps I've used it inside some classes on front-end code, since inside class objects, it almost always refers to what you actually expect it to be, instead of what someone else might've set it to be.

1

u/SarahC Aug 24 '17

In an object function, if there's an event for something like image load... inside the callbacked function, we need to use "that" or whatever name we want to remember the object context in - otherwise "this" is going to be be wrong...

I can imagine even beginners hitting that with copy/pasted code they use...

Do you think it's not that common? I'm just wondering.

1

u/pagirl Aug 24 '17

Yeah. I had an interviewer ask me tons of questions about eval, only to read Douglas Crockford say how bad eval is. Thought about calling the interviewer back and saying "look! Eval is bad anyways!"

4

u/SirHound Aug 24 '17

Unless you're writing a class, there's not a single appropriate usage of this. Apply, call and bind are fine to be understood, I ask about them in interviews to get a grasp of how deep someone's knowledge is. But they are redundant and a candidate would get points for explaining why.

1

u/anton_rich Aug 24 '17

Can you you explain more on why they are redundant? I'm a newbie.

3

u/SirHound Aug 24 '17

Sure

Binding functions to a class used to be popular like this:

class Foo {
  constructor() {
    this.bar = this.bar.bind(this);
  }

  bar() {

  }
}

Which then allowed you to pass this.bar as an argument to be executed elsewhere, knowing this would actually be referring to the current class instance.

Now we can just make bar a property of the class:

class Foo {
  bar = () => {};
}

Another example given elsewhere in this thread was calling a function when you have a variable number of arguments, ie:

const myArray = [1, 2, 3];
Math.max.apply(null, myArray);

Rather:

const myArray = [1, 2, 3];
Math.max(...myArray);

Or currying. Proposed:

var greetingPrinter = print.bind(null, 'hello ');
greetingPrinter('Bob') // hello Bob

Better:

const greetingPrinter = (name) => print(`hello ${name}`);
greetingPrinter('Bob') // hello Bob

2

u/[deleted] Aug 23 '17

I'm doing well for myself without ever having to use any of those methods. Could you provide an example?

3

u/dont_forget_canada Aug 23 '17

If you have a function that takes variable length arguments but you have an array you can do: Math.max.apply(null, [1, 2, 3])

but its also very useful for doing stuff like return someOtherFunction.apply(this, arguments). So you could store a reference to some function i.e. var original = object.method then overwrite that method with something else object.method = function() { /* do new stuff here */ return original.apply(this, arguments) } so now you've managed to create a hook each time object.method runs but you havent effected its behaviour.

9

u/[deleted] Aug 24 '17 edited Aug 24 '17

bind, call, and apply are hacky. You don't them. I promise.

Sending variable numbers of arguments does not optimize well. In fact, much of the time it won't compile at all.

A better solution is to give your function a single argument, which expects to be an object literal. You can populate this variable numbers of items without harming performance. If you wanted to populate your object like an array, fine, you can do this with array notation. You can even populate it in a loop with numbers as keys (though they will be coerced to strings).

Explaining this in the last job interview and why I will never use bind, call, or apply helped me to nail the interview. Out of 72 people actually interviewed during that blitz only 9 were selected and of those 9 I was the only senior.

5

u/Silhouette Aug 24 '17

A better solution is to give your function a single argument, which expects to be an object literal.

What if the function you need to use was written by someone else?

2

u/benihana react, node Aug 24 '17

hey, this guy was the most qualified candidate for the job he applied to. you should listen to him.

2

u/Silhouette Aug 24 '17

I'm suitably impressed. ;-)

2

u/[deleted] Aug 24 '17

Then I would either ask them to change it or I would simply rewrite it myself.

2

u/Silhouette Aug 24 '17

Is that really a sensible position if we're talking about, for example, an API for a library providing some complex functionality?

Perhaps I'm not completely sure what you meant by

Sending variable numbers of arguments does not optimize well. In fact, much of the time it won't compile at all.

before, and we're talking at cross-purposes here?

2

u/[deleted] Aug 25 '17

A better solution is to give your function a single argument, which expects to be an object literal. You can populate this variable numbers of items without harming performance.

Changing shape of an argument can easily cause de-opt. Very wrong to say this won't harm performance.

2

u/[deleted] Aug 23 '17

The first example I would do Math.max(...myArray).

Second could probably be replicated with arrow functions.

1

u/dont_forget_canada Aug 23 '17

nice spread example, for the second one how would you propose rewriting my code using arrows?

Another use (this time for bind) is preserving arguments. If you had some function function print(a, b) { console.log(a + b) } you could do var greetingPrinter = print.bind(null, 'hello ') which then enables greetingPrinter('Bob') //hello Bob. You can do this one with arrows although I find bind in some situations to be very concise.

8

u/[deleted] Aug 23 '17

I find bind less concise personally because it forces you to pass the context of this. It's just... icky, to me. I'd much rather const greetingPrinter = name => print('Hello ', name)

3

u/SirHound Aug 24 '17

All of these examples are better served with simple functional composition. It'd be clearer to read and more flexible (why overwrite existing behaviour when you can compose a new function like your second example?)

2

u/benihana react, node Aug 24 '17

"sure. what happens when you need to use async / await with an arrow function?"

45

u/AndrewGreenh Aug 23 '17

Oh no, not the "pass by reference" discussion again! Javascript is pass by value only, while some values are references themselves, this does not mean that its pass by reference.

32

u/[deleted] Aug 23 '17

If your interviewer asks you about "pass by reference" the right answer is to explain how parameter passing works in JavaScript. You can avoid saying the words "pass by reference" and instead say something like "when objects are passed we receive a reference to the object, so any changes we make to it will persist after the function returns" or whatever.

Correcting the interviewer on terminology probably isn't the right answer, especially since it's perfectly clear what they mean and this (mis)use of "pass by reference" is very common in the JS community.

Nobody wants to hire someone who sees every question as an opportunity to correct you.

2

u/benihana react, node Aug 24 '17

not to mention, pass by reference and pass by values are concepts that existed for decades before javascript even showed up. it might be beneficial to show you have some perspective and don't just solely focus on js.

13

u/cheese_wizard Aug 24 '17

This is pretty close. Both Java and JavaScript do what's called 'Pass by Sharing'. They pass a reference by value, which sounds weird. Basically, the objects methods and values are available through the 'reference', but overwriting the reference (like swap) will only overwrite the local object, not the one it looks like it points to, because it's not a real reference, like in C/C++.

2

u/b4ux1t3 Aug 24 '17

Does that not mean that you're essentially passing a pointer? Which is, at its core, passing by reference? The only difference between this and how C does it it, for example, is that you don't need to use ->?

I'm genuinely asking, I'm not the most familiar with JavaScript.

2

u/TrylessDoer Aug 24 '17

Good point. Here's a code snippet showcasing this:

var _myObject = {hello: 'world'};

function deleteMyObject(myObject) {
	// Or use _myObject without passing a function arg
	myObject.lastFunctionCall = 'deleteMyObject';
	myObject = null; // `delete` keyword doesn't work on object references, so we need to set this to null
	delete myObject;
};

deleteMyObject(_myObject);

// _myObject still exists
// _myObject now equals {hello: 'world', lastFunctionCall: 'deleteMyObject'}

4

u/pgrizzay Aug 23 '17

Isn't that the definition of pass by reference? (to pass a value of a reference)

5

u/HomemadeBananas Aug 23 '17

Nope. If you assign new values to your parameters, it doesn't change the original value where it was passed in to the function. In C or C++ for example that's how pass by reference works.

2

u/pgrizzay Aug 23 '17

yes, if you assign new values to the references, then those references are different. You're still passing the reference though, right? (haven't coded in c++ in a while)

3

u/HomemadeBananas Aug 23 '17

C++ has both pass by reference and pass by value.

-1

u/pgrizzay Aug 23 '17

Okay, then I suppose to appease the purists... Javascript passes primitives by value and the value of the reference for non-primitives.

It's still accurate in my mind to say javascript passes primitives by value and non-primitives by reference.

5

u/HomemadeBananas Aug 23 '17

It's wrong though, because that means something else. It passes references by value.

1

u/pgrizzay Aug 23 '17

In c++ when you pass by value, are you passing the value of a reference?

7

u/BB611 Aug 24 '17

C++ options:

  1. Pass by value - testFunc(int val)

  2. Pass a pointer by value (I think this is most similar to your question) - testFunc(int *val)

  3. Pass a reference - testFunc(int &val)

2

u/SgtBlackScorp Aug 24 '17

I'm actually interested in what exactly the difference between *val and &val is. Could you elaborate?

→ More replies (0)

1

u/Carnilawl Aug 24 '17

In the third case, are you passing any information beyond a memory address?

→ More replies (0)

4

u/cheese_wizard Aug 24 '17

Look up 'Pass By Sharing', a subtle nuance that Java and JS both use... also known as passing a reference by value.

3

u/AndrewGreenh Aug 23 '17

Nope, imagine this: every variable in js is a bucket. When you call a function, you empty this bucket and the contents land in the bucket in your function (the function parameter) you can then take this content and modify it. By the you can never change, what item is in the bucket outside of your function. Sure, if the item is mutable, you can change it and it will change on the outside too, but you can never change, which item is in the outside bucket. In languages where pass by reference is possible, you can reset the contents of your variable. For example, c# has out parameters, this allows you to set the content of a variable that is not inside your function.

10

u/MoTTs_ Aug 23 '17

The issue here is different languages use the same words to mean different things. What JavaScript calls a reference is what C/C++ calls a pointer. So in JavaScript, when you hear "reference," think "pointer." Which means when we say "pass by reference" in JavaScript, it's like we're saying pass by pointer.

2

u/senocular Aug 23 '17

you empty this bucket and ...

You're not really emptying it... ;)

2

u/[deleted] Aug 23 '17

1

u/farm-fresh-js Aug 28 '17

I realize the wording I used may have been confusing for those coming from other programming languages. I've changed the article to remove discussing "pass by reference" in those exact terms. Instead, I wrote that for objects, the reference is copied and passed. Thanks for reading!

6

u/Vheissu_ Aug 24 '17

Maybe just my experience, but it seems the modern hiring process for Javascript/front-end developers is being asked questions like this:

  • Can you solve this complex coding puzzle on this whiteboard for me?

  • Write a bubble sorting algorithm

  • Write a Fibonacci number calculator

  • What's the difference between call and apply?

I rarely have been asked questions relating to the DOM or broad Javascript topics, save for maybe a handful of them. Most Javascript interviews seem to be heavily skewed towards developers with academic mindsets.

1

u/riledhel Sep 21 '17

I do javascript interviews as part of my job and I really like DOM related questions, how events work in browsers and anything that can lead to an interesting discussion about the whole stack. I think that way you can really get a sense of the experience of the other person, how much they care about the details or if they understand the bigger picture.

11

u/stratoscope Aug 24 '17 edited Sep 17 '17

Value vs. Reference — Understand that objects, arrays, and functions are copied and passed by reference. Understand that primitives are copied and passed by value.

This is way off the mark, and it seems to be a very common misconception.

There is no difference in observable behavior between how objects and primitive types are handled when passed into a function. They are treated exactly the same, both when passing arguments into functions and in = assignments.

It's best to avoid terminology like "pass by value" and pass by reference", because they lead to assumptions based on what those terms mean when talking about other languages.

Instead, let's talk about names and things, where a "thing" may be either an object or an instance of a primitive type.

When you pass an argument into a named function parameter, or when you use an = assignment, you are taking a name and making it refer to a specific thing. This is in addition to any other names that may already refer to the thing. Those don't change just because you made yet another name refer to the thing.

Also, these names are specific to each function invocation. If you call a function twice, the parameter names are spelled the same, of course, but in effect each invocation has a brand new set of names.

All of this is true whether the "thing" is an object or a primitive type.

So, why does it seem that they are so different? After all, what if we pass an object into a function and then modify the object inside the function:

var obj = { a: 1 };
fun( obj );
function fun( o ) {
    o.b = 2;
}

This modifies the original obj so it is now:

{ a: 1, b: 2 }

So obviously, the object was passed by reference, right? Contrast that with passing a primitive value into a function and then modifying the value:

var value = 1;
fun( value );
function fun( v ) {
    v = 2;
}

Here the original value hasn't changed at all - it's still 1! So obviously, the primitive value was passed by value, right?

Wrong.

Look more closely at the code. In the first example we have:

o.b = 2;

This adds a new property to the o object. And o is just another name for the object that is named obj outside the function. So both o and obj have changed, because they are the same thing.

The second example is quite different:

v = 2;

We're not adding or modifying a property of v, we're discarding the reference that v originally held and replacing it with a new reference. So now v is a reference to the number 2, but this doesn't affect value outside the function, because we didn't do anything that affects that name.

Suppose we had done something similar in the first example, say:

o = { b: 2 };

Now we're not modifying the original obj object, because we have discarded the reference that o had to it and replaced it with a new reference. o and obj no longer refer to the same thing - just like the "primitive value" case where we changed v to no longer refer to the same thing as value.

Going back to the primitive value case again, what if we tried to set a property on the value?

var value = 1;
fun( value );
function fun( v ) {
    v.b = 2;
}

The assignment into v.b would fail, but not because primitive values are handled differently from objects. It would fail because primitive values are immutable.

The same would be true for an immutable object:

var obj = { a: 1 };
Object.freeze( obj );
fun( obj );
function fun( o ) {
    o.b = 2;
}

The assignment into o.b would fail just like the previous case, but not because it's an object or a primitive value. It fails because the thing that o refers to is immutable.

The purported difference between objects ("passed by reference") and primitive types ("passed by value") is nothing more than an illusion caused by the fact that we don't write the same code when dealing with each.

Update: I wrote this long-winded explanation before I noticed that one of the comments on the article itself covers much of the same ground. But I still think it's useful to talk about "names" that refer to "things" instead of "pass by value" and "pass by reference", just to avoid mental baggage that comes from other languages that use those terms to mean something subtly different.

3

u/FormerGameDev Aug 24 '17

I have implicitly understood all of this for a long time, but was not entirely able to explain it. thank you.

2

u/farm-fresh-js Aug 28 '17

Hi, I'm the author of this article. When I wrote about value vs. reference, I meant to say that the reference is what's copied, as this is the only thing that's possible with JavaScript. I realize the confusion my wording might have caused and I've changed the article. Thanks for your input!

1

u/stratoscope Aug 28 '17

That's great, I'm glad my nitpicks were helpful. I'll revisit the article and let you know if I have anything else to complain about. ;-)

Keep up the good work!

2

u/madcaesar Aug 24 '17

Thanks for this.

13

u/Nullberri Aug 23 '17

Apply Call Bind,

Truth be told you'll use bind 99% of the time and Call and Apply are rare enough you'll probably just check mdm every time you think you might need them. Only to realize you still probably just wanted bind.

0

u/[deleted] Aug 23 '17

[deleted]

2

u/vcamargo Aug 24 '17

Me too, neither call and apply. I've been doing Node+React for the last couple of years and I can't remember the last time I've used bind, call and apply. If an interviewer was pushing too hard this question I'd think the company would be working in this giant pre ES6 monster.

2

u/agree2cookies Aug 24 '17

Senior react developers I've seen use bind extensively... not sure how you're avoiding that.

1

u/Asmor Aug 24 '17

IE11 doesn't support arrow functions. We have a big client that won't let us drop IE11 support. So I still have to use bind. :/ And lots of other fun things I can't use at work, either.

Although I did just realize today that IE11 supports let and const, so... that's exciting. lol

0

u/[deleted] Aug 24 '17

[deleted]

2

u/Asmor Aug 24 '17

We don't even have node.

It was a mighty win when I got my company to adopt sass. And even then, we didn't install ruby. No. We use a c port called sassc.

Sigh...

2

u/elingeniero Aug 24 '17

I praised the lord the day node-sass came out to wrap sassc for node. It was my final ruby dependency after I had replaced vagrant with docker and I was more than happy to be able to uninstall ruby.

Your company made absolutely the right choice there, regardless of how slow to modernise they might be otherwise.

0

u/[deleted] Aug 24 '17

[deleted]

1

u/davidstepo Aug 24 '17

Can you explain in what contexts and situations they utilize bind? It could be some tiny lack of knowledge as I've been working on a project where people have been caught up using bind in a component's constructor (React) way too much and didn't know about the class fields existing.

Not all senior developers are created equal, though.

0

u/[deleted] Aug 24 '17

[deleted]

2

u/davidstepo Aug 25 '17

Darn it, sorry, I replied to the wrong comment.

Thanks for your input into the topic, mate. I gotta be more careful next time.

0

u/[deleted] Aug 24 '17

[deleted]

3

u/Magnusson Aug 24 '17

You don't need arrow functions for that, you can just use currying:

function add(a) {
  return function (b) {
    return a + b;
  }
}

You never need to use arrow functions since they're just shorthand. But this is just a more verbose version of the code in the comment you're replying to. They're both partial application.

2

u/elingeniero Aug 24 '17

It's a nice trick but I'd never use that pattern in a language where it isn't the norm (e.g. Haskell).

For a start, I now need to call add like this add(2)(3) which I don't like, and secondly there's no easy way to construct add with an arbitrary number of arguments. For example, you couldn't write the following function in a curryable way without additional logic:

// Call with add(1, 2, 3, 4)
function add(...xs) {
  if (xs.length == 0) return 0;
  return xs[0] + add(...xs.slice(1));
}

// Partial application 
const add3 = ...xs => add(3, ...xs);

This is important because there are many functions which work like this so knowing how to do it this way is necessary. E.g.:

const max100 = ...xs => Math.max(100, ...xs);

I like the functional style, but I don't think that shoe horning functional patterns into a language without the syntax to support it (i.e. add(2)(3) vs add 2 3 is a good idea when it's not the community norm.

2

u/Magnusson Aug 24 '17

I like the functional style, but I don't think that shoe horning functional patterns into a language without the syntax to support it (i.e. add(2)(3) vs add 2 3 is a good idea when it's not the community norm.

This is what ramdajs is for.

3

u/Buckwheat469 Aug 24 '17

I love explaining this. I have a coworker who was writing an annotator that would wrap a class function (babel, react). He needed to use apply to make sure the this context transferred, but some functions were also bound by the class because they would lose the this context for the class in some cases. Binding the functions would break the this context for the annotations, so we had to develop a nice way to preserve the this context so that that didn't break this.

3

u/[deleted] Aug 24 '17

I'd also know Promises well. During my Amazon interview I was asked to write a Promise.resolve and Promise.reject from scratch

8

u/agree2cookies Aug 24 '17

My Amazon interviewer showed me what an Applicant.reject method looks like when called.

1

u/madcaesar Aug 24 '17

Mind sharing?

8

u/akujinhikari Aug 23 '17

Every interview I've had has had me do some kind of complex math and/or array manipulation: two things I'm bad at. It's always complex bullshit you'll never use in real life though, which makes it even worse, if you can't do it. I've lost out on so many jobs because of this, and it infuriates me. GIVE ME PRACTICAL SHIT TO CODE!

6

u/pentakiller19 Aug 23 '17

Can you give me an example of an interview question you received?

3

u/akujinhikari Aug 23 '17

It's not the interview questions; it's more during the "technical screen," which can be with or without someone "watching." That's in quotes, because once it was over Skype while screen sharing, and a couple of times it was while someone just waited on the phone, which was really weird, because she wasn't technical; her job was to listen to my typing basically and make sure I wasn't... fuck I don't even know - it was over the phone, so I don't know what her purpose was. Either way, if they aren't "watching" and give you 24 hours, those are usually much, much harder questions, because they know you're just going to try and find the answer online.

9

u/nathanjd Aug 24 '17

The perhaps you're applying for the wrong positions? We do algorithms and data structures in our interviews because we need good software engineers. Being able to just code a web app is not sufficient for our problem space. We have a strong brand to protect and an international development team so performance, reliability and maintainability are the primary concerns.

It's also not feasible to test a candidate's practicality in a short interview. Sure, I like to do a small data structure operation on the whiteboard but that's really something you have to find out after hiring.

I'd personally look for positions for "web ui developer" or "web ui developer intern" as that's where I started! Also, do you have a portfolio I could look at? It can go a long way towards showing your practicality. Ultimately though, programming is math and you'll need to learn those skills if you want to advance a career in web development. If you want to stay just front-end, you could limit your data structure knowledge to:

  1. Arrays. The primary data structure you will interact with the make a web app. Think getting results from a REST API or validating a user form.

  2. Maps. Everything in javascript is, in essence, a hash map. These will become your best friend when trying to optimize the performance of your application.

  3. Trees. This is the most complex but necessary. Your entire web page is represented by the DOM which is a tree of nodes. You'll need to know how to efficiently traverse and modify this tree to make the page interactive.

It would be hard to imagine a day when I did not work with those data structures for front end web dev. I'd be happy to answer any questions you have.

8

u/dvlsg Aug 24 '17

I agree with most of that, but I'm not convinced that mastery of trees is required to know how to work in the front end. Especially with tools like React.

For example, if you asked me the last time I had to determine whether to use depth-first or breadth-first traversal to search for something in the DOM, my answer would be "never".

2

u/nathanjd Aug 24 '17

Fair enough, it probably is not high priority for most. Though I am on a team whose main focus is client performance so we investigate and write tools for our devs to help them better understand how the dom updates and cpu time underneath React work. Trusting the DOM diffing engine to do the right thing can only take you so far. Particularly if you have nodes being marked as dirty too high up in the tree which is the most common pitfall I see.

3

u/wavefunctionp Aug 24 '17

It's been my experience that people don't look at your portfolio. I've had maybe half a dozen clear hits on my portfolio website from potential employers.

You either make it past the resume screening and get a phone interview to talk about your experience/projects or you hear nothing.

This over a hundred applications over 8 months in a 4 state area. Basically anything that doesn't say senior developer, and few that do but match very closely with my skills, but not total experience. This landed dozen or so calls from HR, about half that from an actual technical lead, and a couple of technical interviews. You never get feedback even when requested.

I don't where people get this notion that there is a shortage of developers. If there were, I'd be getting more calls, the salaries would be higher, and the requirements would be lower.

2

u/nathanjd Aug 24 '17

For me personally, a portfolio is the most important piece. Even better if they've been active on github. However, I don't come into the interview loop until rather late in the process, after tech screenings. So I can't speak too much to that first layer.

What I can confirm is that it is hard to find really good front end engineers. Recruiters often do a poor job in tech screening so they end up wasting a ton of our time on garbage candidates. In my conversations with others attempting to hire in our industry, there seems to be a large divide in the skills we're looking for.

On one side, we want strong engineers. There are plenty of these out there, fresh out of college, but most are used to... real languages. They wouldn't touch front end web with a 10ft stick and I don't blame them. The confluence of a shitty (but improving) language and varied browser ecosystem is a bit of a nightmare. And that's without mentioning the increased pay they would get doing anything but web development. In short, good engineers often lack practical experience with front-end web technologies.

On the other side, we want experience with web technologies. The amount of domain knowledge required is rather high for the web so it's often not feasible to hire a good engineer then train them up on the front end. These candidates with experience are your "script kiddies", often self taught with no engineering experience which is where I started. Unfortunately they often have problems working on a team in an enterprise environment or meeting our performance and quality targets.

Who we really want to hire is someone in the middle of these two extremes, which has proven hard to find. However, if you have a strong portfolio and can sell yourself as a candidate that possesses both, you should get more real interviews. Though I do not perform phone screens so am not sure what would be most helpful there. In general, we prefer strong CS fundamentals over experience.

3

u/vcamargo Aug 24 '17

TIL programming is math

2

u/proskillz Aug 24 '17

Couple suggestions:

  1. watch lectures or read up on algorithms

  2. Read Cracking the Coding Interview

  3. Practice solving these types of problems on leetcode or hackerrank.

2

u/phpdevster Aug 24 '17

In addition to higher order functions, being able to explain pure functions and their benefits is one I've come across in every JS interview I've ever had.

1

u/farm-fresh-js Aug 28 '17

I'm the author of this article! Awesome to see that it's useful. Thanks for reading!

0

u/[deleted] Aug 24 '17

[deleted]

19

u/RotateElectrolyte grammin' the 'puters Aug 24 '17

Right? It's like the whole problem with teachers teaching to standardized tests. It seems to me most good JS software is written by people bringing concepts from other languages - who realize they're working with a shoddy bastard child of the browser wars.

5

u/am0x Aug 24 '17

Let's say you have a seasoned software engineer going into a JavaScript interview for a job he is grossly overqualified for in terms of development experience. These are the types of questions that would throw him off. However ask him basic programming concepts and he would smoke any of the other candidates.

Learning a language is easy when you understand the fundamentals of programming. Learning the quirks are even easier.

4

u/FormerGameDev Aug 24 '17

Probably depends on the environment. If you're being hired for a Javascript specific job, they probably really want you to know Javascript. My current job started supposedly as a Javascript/HTML, but my first day, I was in C++ land (a place I hadn't been in 20 years), so that was certainly fun and entertaining. I've now worked with upwards of 7 different languages in a single day. It's been .. . interesting.

2

u/kenman Aug 24 '17

I think a counter-argument would be that sometimes you just need a butt in the seat, someone who's not going to be architecting anything soon, but more-or-less doing mundane bug fixes and smallish features.

Yes, in a perfect world with unlimited hiring capital, we'd all be hiring the cream of the crop, but in reality, sometimes it's better for the org to hire 2x $50k developers than it is to hire 1x $100k because it's more about the breadth of the work than the depth.

2

u/phoenixmatrix Aug 24 '17

While I generally agree, a great developer will adjust to the specific environment.

I see far, far too many people writing C# like they do Java (the 2 only LOOK similar, but they have subtle and extremely important differences) or JavaScript like they do C# and so on.

Languages are just tools, but they are tools with very large amounts of subtleties.

Eg: If you're writing Java, you're going to be using classes. If you're using JavaScript, you MIGHT be using classes. Understanding why it's not always the case is important: if you just blindly follow the paradigms you're used to, you'll write shit.

I don't care if someone know how to use prototypes when they code, but I still have to ask if they're aware of these things. Why? To make sure they understand why some patterns are the way they are in our code base.

3

u/madou9 Aug 24 '17

How about understanding both?

1

u/dudeguy1234 Aug 24 '17

Any tips or resources for learning about software architecture? I've been a programmer for a long time and write code in my current position but I'd like to eventually move into software development.

1

u/slapfestnest Nov 02 '17

just to be that guy: "factoid" actually means usually-false information that is repeated so often that people just assume it's true

0

u/bent_my_wookie Aug 24 '17

I'd hire you based on that comment.

0

u/[deleted] Aug 23 '17

[deleted]

4

u/theginger3469 Aug 23 '17

Clever and unintrusive, I like it! Those full-page modal "subscribe to our newsletter" modals are Satan.

2

u/RedditWithBoners Aug 23 '17

Unintrusive perhaps, but I'm disappointed I fell for it.

0

u/[deleted] Aug 24 '17

[deleted]

3

u/aveoon Aug 24 '17

Also as an engineering manager that does a shit ton of interviews, I also agree. There's are all basic things to understand about JS.

1

u/benihana react, node Aug 24 '17

i'm also a very experienced interviewer (i guess? i dont know i never really thought to quantify experience interviewing) and i'm wondering why you think that. the fact that there are blog posts like this that tell you what to memorize makes it a pretty bad set of questions in my opinion.

0

u/[deleted] Aug 24 '17

[deleted]

1

u/larholm Aug 24 '17

Everyone struggles, it's difficult to share knowledge. Practice helps.