Common JavaScript Interview Questions that Interviewer asked an Interviewee

mousumi mitu
3 min readMay 8, 2021

A developer who is a front-end or backend all faced questions related to javascript. So, today’s topic is about some common javascript interview questions.

  1. Truthy & falsy values: first talk about falsy values- 0, empty string, undefined, null, false all are falsy value and expect those all other values are truthy value. If you put 0, false, space inside a “” then it will count those values as truthy values.
  2. Undefined vs Null: what is undefined? in simple terms if you don’t define anything then you will get undefined. In javascript, there are several ways to get undefined- if only declare any variable but not set the value, not return the function, declare 2 parameters but pass only one value, for an object don’t pass property values. On the other hand, null occurs when there nothing existed or empty.
  3. Double equal vs Triple equal: for assign value of any variable javascript use one equal sign but double equal use for comparison. For the conditional purpose if you use double equal it will only compare the values and try to convert them to become two things equal. But triple equal strictly evaluates everything, it also checks the type of the value.
  4. Scope, Block scope & access outer scope: if something declares between a function then its scope will be inside the function only. By declaring something outside the function it will become a global scope. We use ‘let’ ‘const’ with a variable in block scope it will give an error for accessing outside the block scope but using the var keyword can get access outside the block. Var has the ability to get access in the parent scope.
  5. Difference between call & apply: when an object has a method that another object wants to apply for that can be used ‘call’ or ‘apply’ methods. Call used the first argument as a this and passed parameters separated by a comma and apply method send all parameters into an array.
  6. Window, global variable: everything that is set in the window becomes a global declaration that means it can easily get from anywhere. Variables also become global when it declares outside the function or when forget to put keywords before the variable name.
  7. SetTimeout & setInterval: its work as asynchronous orders give results after executing other work according to its timer value. Even if you set the timer to 0 still execute last. SetInterval called the function repeatedly regarding its timer value if you set 5 seconds then execute every five seconds until stopped the function.
  8. Javascript event loop: To work on multiple tasks simultaneously Javascript has a model based on an event loop. When we a function it goes to the stack part where JS added the tasks one by one and execute it from the top. In this model first, it’s done synchronous work after it goes to asynchronous works like setTimeOut that are waited in the queue section.
  9. Event bubble: for example create a todo list inside a div and add an event handler onclick for both div and list items now if you clicked only list item it also executes the div event handler. This is called an event bubble, it tries to get up and execute every possible event until its reaches his parent div.
  10. Stop propagating event bubble: After getting knowledge of the event bubble you might want to stop this, for stop propagating event bubble there are 2 ways one is to stopPropagation() and another one is stoImmediatePropagation().

--

--