10+ JavaScript Interview Questions

Prologue

A few days ago, I connected with a senior software engineer, who is also a bootcamp grad. He was kind enough to offer mock interviews with recent bootcamp grads from LinkedIn. The questions he asked were commonly seen in his interviews and his peers.

I was, of course, quite nervous about the interview, since I have been using most of my job searching time networking and studying data structures and algorithms and had not been refreshing my knowledge in vanilla JavaScript. Thankfully, the mock interview went better than I thought, since I was able to answer ~75% of the questions. However, my feedback was that I should be more concise with my answers and use more technical terms. Therefore, I decided to use this article as a refresher and my learning tool as a direction to answer with the right keywords for each question :)

Questions and Answers

Make sure to at least answer something even if you don’t know and acknowledge that to your interviewer!

1. What are some primitive data types?

string, number, bigint, boolean, undefined, symbol and null

2. what is the difference between undefined and null?

null is an assigned value and undefined means a variable has been declared but no value.

Note: I wrote a blog about null and undefined a while ago with the bonus section of new ES2021 feature, go check it out if interested!

3. what is the difference between undefined , null and undeclared ?

On top of the answer above, undeclared means a variable has been declared without the var / let / const .

🏁 + 🚗 + ⛽️

4. There are multiple ways to declare a variable, can you tell me them?

var / let / const

5. What is the difference between var, let, and const?

  • var : globally scoped; can be reassigned, redeclared, updated; will get undefined with “hoisting”
  • let : locally (function/block) scoped, cannot be reassigned and redeclared, but can be updated; will get Reference Error with “hoisting”
  • const : locally (function/block) scoped, cannot be reassigned, redeclared and updated; will get Reference Error with “hoisting”

I also wrote a blog discussing the difference between all three of those. Feel free to check it out if interested!

🐀 + 🍅 + 🧑‍🍳

6. Can you describe what “hoisting” means?

Hoisting is a JavaScript’s default behavior of moving declarations to the top. (W3Schools Definition)

💪 + 💥 + 👓

7. What is a callback function?

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. (MDN)

📖 + 🤠 + 🧑‍🚀

8. What are some ways of handling asynchronous behavior?

Promises , async , await

Guide from MDN: Asynchronous JavaScript

🔎 + 🐠 + 🦭

9. What is the difference between ==and ===?

==: checks for value equality and performs type coercion (i.e. converts the types of the variables to match each other) before checking the values.

=== : does not perform type coercion; evaluate whether the variables being compared have both the same value AND the same type

3 == "3" // true
3 === "3" // false

Resource: JavaScript Triple Equals Sign VS Double Equals Sign — Comparison Operators Explained with Examples (FreeCodeCamp)

🚪 + 😱 + 💡

10. What is the “DOM”?

The Document Object Model (DOM) is a programming interface for HTML and XML documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects (MDN).

Credit: Timothy Robards (Medium)

11. What are a few ways you can grab an HTML element from the DOM?

  • Gets ID: getElementbyId() . Ex: getElementbyId(#inspiration)
  • Gets Class: getElementsByClassName() . Ex: getElementsByClassName(.container)
  • Gets Tag: getElementsByTagName(). Ex: getElementsByTagName('div')
  • Gets Selector (Single): querySelector()
  • Gets Selector (all): querySelectorAll()

12. What is the return structure of a document.querySelectorAll?

This returns a static (not live) NodeList representing a list of the documents’ elements that match a specified group of selectors (MDN).

This is what I got when I typed that on the console of the MDN page.

Conclusion

Certainly, there were a few questions that completely caught me off guard. However, the mock interviewer was really patient with me and explained everything to me. I highly recommend to do at least 1 or 2 mock interviews with your peers, or someone you know who is willing to help! Good luck with your interviews!!

Also, in case you haven’t noticed those emojis, I hope you will be able to guess what movies they represent along the way — and yes they are all Pixar movies:

  1. 🏁 + 🚗 + ⛽️ = Cars
  2. 🐀 + 🍅 + 🧑‍🍳 = Ratatouille
  3. 💪 + 💥 + 👓 = The Incredibles
  4. 📖 + 🤠 + 🧑‍🚀 = Toy Story
  5. 🔎 + 🐠 + 🦭 = Finding Dory
  6. 🚪 + 😱 + 💡 = Monster Inc.

That’s all I got today and thank you for being a wonderful reader!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store