Top 10 JavaScript interview questions

This article will discuss the top 10 questions that every js developer needs to know to excel in any interview.

Example of truthy values and false values

Any number is truthy other than 0. Any string is truthy other than an empty string. A white space inside a string, 0 inside a string are examples of truthy values. Undefined, null, NaN is falsy values. Empty array and objects are truthy.

How to get undefined?

If we declare a variable but don’t put any values, then it's undefined. If we call a function, but that function does not return anything, write return keyword but don’t tell explicitly what to return, if we want a property from an object which does not exist in the object, if we set the value of a variable undefined (not recommendable at all) then we get undefined.

Difference between double equal and triple equal

Double equal checks the value only, but triple equal checks value and data type both.

What is hoisting?

If we declare a variable inside a scope using let/const, that variable is not accessible outside of the scope. But if we use let, then we can access that variable from any place in the code. It is because of hoisting. In summary, hoisting takes the variable to its parent element to be accessible from any place.

How to find the largest element in an array?

Remove duplicate item from an array

Reverse a string

Swap variables

Sum of numbers

Check if a number is prime or not

To be or not to be that is the question.