Top 10 JavaScript Interview Questions

Muhammad Shahnewaz
JavaScript in Plain English
3 min readMay 8, 2021

--

If you want to be a JavaScript programmer, you must know these things.

1. What are the Truthy and Falsy values?

Answer: A truthy value is like true and a falsy value is like false. These are as follows:

falsy values -> 0, “”, undefined, null, NaN, false
truthy values-> “0” , “ “, [], {}, ‘false’

So, If we use one of these values in the if-else statement then we will get the same output which is shown below. In this given example, I will show you these values using ternary expression inside the console.log() method.

Examples:

falsy-truthy values

2. What is the difference between null and undefined?

Answer: Firstly, null means an empty or non-existent value. It is supposed to be something that doesn’t exist. It can be assigned to a variable as a representation of an empty value.

On the other hand, undefined means a variable has been declared but its value has not been assigned. In the function, If we don’t pass the parameters, it shows undefined.

Example:

3. What is the difference between double equal (==) and triple equal (===)?

Answer: Double equal ==is an abstract equality operator. It checks whether its two operands are the same or not by changing the expression from one data type to another.

On the other hand, Triple equal === is a strict equality operator which returns false for the values which are not of a similar type. Triple Equals does not perform type coercion.

Example:

4. What is 'this’ keyword?

Answer: It refers to an object which is executing the current bit of JavaScript code. While executing every JavaScript function has a reference to its current executing context, it's called this.

Example:

5. How to check for a prime number?

Answer: A prime number is a natural number that is only divisible by 1 and itself. For example 2, 3, 5, 7 are the prime number. On the other hand, 4 is not a prime number because it is divisible by 1, 2, and 4 itself.

Example:

6. Find the largest element of an array?

Answer: We can find the largest element of an array using the for-loop method.

Example:

7. How to use the JavaScript callback function?

Answer: In JavaScript, we can pass a function as an argument to a function. This function that is passed as an argument inside of another function is called a callback function.

In this given code, there are two functions and while calling the greet() function, two arguments (a string value and a function) are passed.

Example:

8. What is the difference between the Let and Const?

Answer: In the Es6 version of JavaScript, variables can be declared in two more ways. The first is that we can declare a variable with the keyword let.

By applying the keyword let we can change the value of the variable more than once. If we use the keyword let in a block scope then we will not access it outside of this block scope. We can also declare a variable by applying the keyword const. But its specialty is that the value of the variable cannot be changed more than once.

Example:

9. What are the advantages of the Arrow function?

Answer: The arrow function is a method of shortcut to the function declaration. It will basically shorten our function syntax.

Example:

10. Closure in JavaScript:

Answer: When a function is able to remember and access its lexical scope even when that function executing outside its lexical scope.

Example:

More content at plainenglish.io

--

--