Photo by Steve Halama on Unsplash

Reflections from a JavaScript Interview

Kelsey Shiba
JavaScript in Plain English
6 min readDec 27, 2020

--

I have now had a few interviews on JavaScript. While I wait to hear back and evaluate, I want to write down what I learned and a few tips for those of you who are looking forward to your JavaScript interview.

Technical Questions

I had a few technical questions that I’ll share. Here was one of the problems I was asked to solve (as I remember it).

Take a string such as "supercalifragilisticexpialidocious" and return an object that holds the letter and the frequency of each letter.For example, if the string = "puppy" the returned object would be
obj = {
p: 3,
u: 1,
y: 1
}
const string = "supercalifragilisticexpialidocious"function createObj(string){
const obj = {}
const array = string.split("")
array.forEach(letter => {
if (obj[letter]){
obj[letter]++
} else {
obj[letter] = 1
}
})
return obj
}
createObj(string)

Link to Repl

Reflections:

Talk Out Loud

The interviewer in this case was really informative. As I created the solution I talked out loud, which I think was also important. I did not initially start with the forEach iterator. I let the interviewer know that my gut told me that “forEach” would work, but if I were solving for brute force I would go with a “for” loop. He immediately chimed in saying that the forEach was the right way to go, so I continued on.

I was really focused on what the end result was. I went into the problem with nerves, but I knew that I needed to return something. I would put that in my notes as I sort of repeated it back to the interviewer.

//function takes a string
//returns an OBJECT
//constraints: word would not exceed 1,000 letters

Beginning & Ending

Then I would write out my beginning and ending and frame the solution:

function createObj(string) {
const obj = {}
return obj
}

Be Open to Learn New Information

My interviewer also mentioned that there was a problem with this piece of code because we are not checking to see first if the object already has the letter.

if (obj[letter]) 

My interviewer introduced me to a new JavaScript object method — hasOwnProperty. Definition here. It returns a boolean if the object has that property (true) or if it does not (false). Here’s the refactored code with this being utilized.

const string = "supercalifragilisticexpialidocious"function createObj (string){
const obj = {}
const array = string.split("")
array.forEach(letter => {
if (obj.hasOwnProperty(letter)){
obj[letter]++
} else {
obj[letter] = 1
}
})
return obj
}
createObj(string)

It was like getting a new bike for Christmas. I did not know that this even existed, and I was ready and willing to learn from it. SO AWESOME. NERDY— but awesome.

Another short technical example

I was asked to write the function for this function call:

multiply(4)(5)

So — I wrote it out while talking to myself:

//needs to return the integer 20 when called
//function name needs to be multiply
//appears to be a double function needed

Wrote my beginning and end (what it needs and what it returns)

function multiply(num1){
return num1 * num2
}

Then added in logic because I knew in order to call the 2nd number into play I would need another function with another argument.

function multiply(num1){
(num2) => {
return num1 * num2
}
}

However, I was missing one thing that often gets forgotten. I needed to RETURN a FUNCTION first in order to include the 2nd argument. Here is the code:

function multiply(num1){
return (num2) => {
return num1 * num2
}
}
multiply(4)(5)

Reflections:

Refactor!

Don’t forget to refactor after. Arrow functions have implicit return, so I could’ve made this function even shorter:

function multiply(num1){
return (num2) => num1*num2
}

However, I needed to see both returns to be sure I understood what was happening under the hood.

Don’t Skip the Fundamentals

I had been working so hard on algorithms and creating my own portfolio that I forgot to go back and do some studying. I was asked some really basic stuff that I could not articulate in a way that I was satisfied with while doing the interview.

One of the questions was: “Was does the ES6 stand for in JavaScript?”

I honestly did not know. I knew that the year was 2015, and that there was another one forthcoming. I guessed that the “S” stood for “syntax” and that the 6 was the version. As it turns out, ES is ECMAScript, and it is the 6th version.

After letting it percolate for a while, I realize what an interesting interview question it was. Will I really be asked this in my every day work at my prospective job? Maybe — not likely. However, it shows that I’ve been curious enough to want to know about JavaScript. To have been exposed to it or wonder about how it works, where it came from. It almost seems like it could be more of a personality question than a technical one.

Another question: What is the difference between classes and prototypal inheritance?

I kind of understood this, but I couldn’t articulate it. I feel like I kind of blacked out during this part of the interview. The point being — I agonized about it later. There’s a great blog about it here.

Another Question: What is special/unique about the arrow function?

I remembered several specific use cases for the arrow function, and that it was used frequently with DOM events in JavaScript because it could bind the keyword this to whatever object created the function. I forgot that the arrow function also has implicit return — which I thought would’ve been an important point to make to my interviewer.

Technical Question: If I had 100 integers stored in an array, what is the best way of going about returning a sorted array without duplicates? This question was also presented as a verbal answer, not to be written in code.

I kind of froze up on this one. I mentioned the built in function sort, but the making it unique or without duplicates kind of stalled me for a moment. More on this below.

Reflections:

Have a Code Area Open

A lot of these questions did not come from a formal technical interview, it was more the “get to know you” interview. I am also a visual person, so when I attempted to work on the array to answer the questions, it was nice to have a coding sandbox open to work on it so I could talk through my answers.

Learn About ES6 Built Ins

When looking into making the array without duplicates, there’s a LOT of ways to handle it. However, after all those ES6 focused questions I realized there may have been an answer that would’ve shown off my ability and knowledge of ES6. There’s a Set object in ES6 that returns a unique set (no duplicates). So, for that last technical question I could’ve used or tried something like this:

const array = [1,5,4,2,1,1]function sortNoDups(array) {
const newArr = array.sort()
return new Set(newArr)
}
sortNoDups(array)

Use and Learn Technical Terms

I struggled with using the correct terms to describe things during the interview, and this is something I want to improve upon. I think there are some descriptions that are move efficient than others, and of course — it depends on your personal preference. For example, when answering the question about differences between classes and prototypes in JavaScript, I could learn and practice saying things such as “classes are like a blueprint of objects and methods for that object to be created.”

Or in regards to this in JavaScript — I really struggled to find the right word for it. But, it seems it is most referred to as “the this keyword,” which I can use moving forward to broaden my ability to articulate what it does and how it works.

Other terms like “implicit return” in talking about the arrow function are also handy, but I want to get to the point where I’m able to speak about such functionality off the top of my head.

Summary

I hope you take this article and use it to your advantage. I learned so much from interviewing and I was grateful for all the experiences I gained. Best of luck to all of you out there.

Code on! ~ Kelsey

--

--