DEV Community

Discussion on: Technical Interview Questions - Part 1 - Javascript

Collapse
 
oculus42 profile image
Samuel Rouse

Thanks for writing this! A lot of technical interviewing questions can be tricky or "gotcha" questions, but these are real foundational knowledge and you go into good detail on your answers.

There are a few small issues that might be addressed.

Anonymous Functions

In the description of arrow functions, you say, "Arrow functions can be anonymous". This is true, but it is not unique to arrow functions.

// Fully anonymous
window.addEventListener('message', function (event) { /* ... */ });

// Technically anonymous (Name assigned automatically)
const addTwo = function (value) { return value + 2; };

// Not anonymous, name separate from variable
const addFour = function add4 (value) { return value + 4; };
Enter fullscreen mode Exit fullscreen mode

We don't usually think of the second one as anonymous because years ago browsers (Chrome first, I think?) started assigning the variable name to an anonymous function to make stack traces more useful, but it is technically anonymous.

this in Arrows

Very minor but depending on the context in which you run your example code, you might not see undefined for the name. A browser's default context is window, and window.name is usually an empty string. The example works as you specify in Node or Deno, though in Bun it will throw an error because the default context is undefined, so this.name cannot be read.

Promise Hell

This is something most people wouldn't take issue with, but I really like promises, so much that my first DEV article was about promises. Nesting .then() is usually an anti-pattern, and in the example case, we can just as easily write this:

function1()
  .then(function2)
  .then(function3)
  .then(function4)
Enter fullscreen mode Exit fullscreen mode

I know a lot of people prefer async/await because it's more comfortable for them to read, but promises get some bad press, in my opinion.😭

Prefer MDN

As a last bit, I strongly recommend using MDN over w3schools as a source for definitions and documentation. W3Schools has improved over time, but has been known to have out of date or inaccurate content. MDN is basically the manual for the web.

Again, thank you for writing and sharing this. and I look forward to seeing more content from you!

Collapse
 
giulianaolmos profile image
Giuliana Olmos

Hello Samuel!! 😃
I was expecting feedback, but not this much detail!
I'm really happy with all the clarifications and examples you gave me. Thank you so much for taking the time to correct and explain everything. 🫶🏻 The goal of this post is to help others with their interviews, and I definitely don’t want to make things harder for them. 😅
I’ll make sure to fix everything and avoid these mistakes. 💪🏼