Top 10 questions of js

Tashfia Hoque
2 min readMay 8, 2021

Question 1. How you differentiate between undefined and null in js?

Answer. During coding, we can get undefined output when we don’t declare values in variable, we try to excess the value from an object or array that is not available. In case of null if we intentionally set the variable value null means nothing is here.

Question 2. What you will use, == or === for comparing variables in js?

Answer. I will like to use ===, because here variables value and type both are checked, as a result we can get error free output. On the other hand == is not so strict like === because it only compares the value not data type which sometimes can create confusions in output.

Question 3. What is hoisting in js?

Answer. Hoisting in js means that declaration of variables or functions pulling top on script so that it can accessible from anywhere.

Question 4. What do you know about call and apply in js?

Answer. Suppose a object has a method and another object wants to use that method. For achieving this we can use bind, call and apply with the existing method. There is a difference in using call and apply. When we use call, we pass this and arguments separated by comma. In case of bind we pass this and arguments as an array.

Question 5. What is this keyword in js?

Answer. In which context the object or method is called will apply to execution context, this keyword works like that in js. If this used alone, it refers to window.

Question 6. What is the difference between setTimeout and setInterval in js?

Answer. setTimeout will work when it asked to perform. setInterval will repeat the work after given interval time.

Question 7. How will you remove duplicate items from an array?

Answer. The easiest ways to achieve this first declare a new empty array and then add the elements of existing array where it has duplicate item by checking the element added before or not. We can achieve this by adding the elements according to their index.

Question 8. How will you reverse a string in js?

Answer. First I will declare a variable with empty string, then a loop to get every element by index. After that I will add every element with empty string variable, here a small trick i have to add every element and then empty string variable.

Question 9. What is recursive function in js?

Answer. In recursive function the function calls itself and stops when the initial or stopping condition met.

Question 10. What is event bubbling in js?

Answer. Event bubbling process starts with the element that triggered the event and then bubbles up to the containing elements in the hierarchy.

--

--