Javascript Interview Questions You Should Know

Abid Hossain
3 min readMay 21, 2021

Anyone can agree with me that a job interview is one of the most intimidating experiences for a web developer. It can be frustrating as well if you are caught off guard. So, it’s wise to make preparations if we really need to crack it. Here are 10 important interview questions a JavaScript Developer should know.

1. What are the Truthy and Falsy values?

If we try to make it simple, truthy is the expression that evaluates the true value of the boolean data. And falsy is the expression that evaluates false boolean value.

Some falsy values are false, 0 , -0 , 0n , “” , undefined, null, and NaN. You can consider all the others as truthy values.

2. Difference between null and undefined

Null usually refers to a value that is empty or doesn’t exist at all. And undefined means a variable is declared but the value or the output is not defined.

3. Solve some problems

Solving problems might be the first question for you in a developer interview. If you want to stand out from the crowd, you must have the basic problem-solving capability. Here are some of the common problems you might be given in an interview.

  1. Remove duplicate items from an array.
  2. Find the largest element of an array.
  3. Reverse a string.
  4. Count the number of a word from a string.

4. Analytical Problems

If you apply for a senior post, you might be asked to solve some problems that require advance analytical skills. Some of the examples are given below:

  1. Create a Fibonacci Series using for loop.
  2. Calculate the Factorial of a number using for loop.
  3. Calculate Factorial in a Recursive Function.
  4. Check whether a number is a prime number or not.
  5. Create Fibonacci Series in a recursive way.

5. How to use DOM and EVENTS?

You must have a good grasp of DOM and Events in JavaScript. You can create attributes and new elements by using DOM. Also, you can make changes in current elements and attributes or remove something using DOM.

Here are some attributes which is used in DOM.

  1. getElementById: To access elements and attributes whose id is set.
  2. getElementByTagName: To access the element’s tag.
  3. innerHTML: To access the content of an element.
  4. getElementById, innerHTML Example

6. Double equal vs Tripple equal

By using double equal, you can compare values. We use triple equal for the same purpose. However, it does check both the type and value. It will return false if the type doesn’t match.

7. Global Scope, Block Scope

In a browser, the global scope is controlled by the window object. In Node. js, it’s controlled by the global object. Block scopes are what you get when you use if statements, for statements.

8. Bind, Call and Apply

Call( ): The call() method creates a function with a given ‘this’ value and arguments provided one by one.

Apply( ): Invokes the function and allows to pass in arguments as an array.

Bind(): It returns a new function that allows you to pass in an array and any number of arguments.

9. Closure

const add = (function () {
const counter = 0;
return function () {counter += 1; return counter}
})();

add();
add();
add();

// the counter is now 3

The variable add is assigned to the return value of a self-invoking function.

The function sets the counter to zero (0) and returns a function expression.

This way add becomes a function. And it can access the counter in the parent scope.

This is called a JavaScript closure.

That’s it for this article. Hope it helps you to rock your interview. Good luck and happy coding.

--

--

Abid Hossain
0 Followers

Programmer | JavaScript | React Developer