10 JavaScript Interview Questions

sonia dumitru
Nov 4 · 4 min read

Who does not love the interview process and the variety of questions every interview comes with?

I’ll be short and concise about 10 technical JavaScript questions I was asked so far during interviews.

1. Tell me about HTTP:

  • is a request -> response protocol, where you have a client-server type model; the web browser is the client that makes a request, which is a HTTP message to the server. The server interprets this and returns back with the format that is it’s fit depending on the route (HTML, image file, json response).

2. What is CORS (Cross-Origin Resource Sharing) mechanism?

  • is a policy or procedure for allowance to the server to describe what’s coming in and in preventing things like other origins; like preventing your website from sharing resources or preventing another website from hitting yours as well.

3. What is .this?

  • .this refers to where the function executes vs where is defined; .this is context dependent
  • call() & apply() allow us to borrow functions and set the .this value on function invocation; bind() creates a new bound function, is a copy of the given function with the specified .this value and initial arguments, you can get around by using an arrow function.

4. What is a CLOSURE?

  • combination of functions bundled together (enclosed) with references to it’s surrounding state (lexical environment)
  • in other words gives you access to an outer function’s scope from an inner function; the inner function will have access to the variables in the outer function’s scope even after the outer function has returned
  • used to enable data privacy

5. What does PROTOTYPE mean?

  • JavaScript is often described as a prototype-based language; prototypes are mechanisms which JS Objects inherit features from one another
  • inheritance is based on it’s prototype, so objects can inherit methods from the parents prototype

6. Explain ‘use strict’

  • it prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining access to the global object)
  • strict mode makes it easier to write “secure” JS
  • eliminates the .this coercion; without ‘strict mode’ a reference to .this value of NULL or undefined is automatically coerced to a global which can cause bugs
  • you will get a syntax error in ‘strict mode’ when: created a duplicate property names or argument names; forbids octal syntax and setting properties on primitive values; makes impossible to accidentally create global variables

7. NaN in JavaScript

  • how you can check if a value is NaN? => .isNaN() method returns true if the value is of the type Number and equates to NaN, otherwise false

8. What is a Promise in JavaScript?

  • is an object that may produce a single value some time in the future; either a resolved value or a reason that it’s not resolved
  • important to know that a promise may be in 3 possible states: fulfilled, rejected or pending

9. What is a CALLBACK HELL and how can you avoid it?

  • refers to the execution of multiple asynchronous operations one after another
  • to avoid: use proper names, avoid anonymous functions, create modules, don’t nest functions, use function hoisting, handle every single error in every single callback, move functions at the bottom and then in different files

10. Tell me about SCOPE

  • a function creates a closure in JavaScript and thus creates a scope. For example: a variable defined exclusively within the function cannot be accessed from outside the function or within other functions.

Good luck!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade