10 Important JavaScript Interview Question

Photo by Emily Morter on Unsplash

1. Null vs Undefined

2. double equal (==) vs triple equal (===)

3. Truthy and Falsy values

4. Difference between bind, call and apply

5. Understanding the this keyword

6. Using of Async Await

7. Find Largest Value of an Array

8. Sum of All Number in an Array

9. Remove duplicate Item from an Array

10. how to Do reverse a String

1. Null vs Undefined

  • We can find undefined in many ways but null is a special type and if a developer set the value of something to null and then we can get the value null.
  • so, first let’s see how can we get undefined form a value, easy one is when we declare a variable and don’t set anything to it and if we log that variable we will get undefined.
  • another way of getting undefined is when we set intentionally a variable value to undefined we will get the value undefined.
  • I will give another example that when we declare a variable inside a function and don’t return form it and call for that variable instead we will get undefined

2. double equal (==) vs triple equal (===)

  • Well, double equal vs triple equal is a interesting subject of javascript.
  • when we call compare two variable with double equal we just compare the value of those two variable.
  • But when we compare two variable with triple equal we compare the value of those two variable with the type of the variable also. that’s the easy way to understand.
  • If I say in details or a tricky way that when we compare two value with triple or double equal we will try to convert the second variable in the type of first variable and then check both are same or not…. in this case double equal just check the value and… triple equal check value with type

3. Truthy and Falsy values

  • It is very much interesting topics for the beginners that to know which value is truthy and which are falsy.
  • There are some falsy value and rather then the falsy value all values are truthy value.
  • let’s first know which are falsy value, example:- 0, false , empty string , null , undefined , NaN. this values are falsy value . rather then them all other values are truthy value

4. Difference between bind, call and apply

this three things are the most confusing things after this in javascript to me.

so first let know about bind, what bind do. bind just do if any function are declare inside a object and we want to use that function with other object we just can bind that function with that object. pretty confusing but after seeing the example it will be cleared

  • what call does is pretty much similar what bind does but in easier way and in a very effective way.
  • apply also do what call can do… but it will take parameter as a array this is the different between them

5. Understanding the this keyword

I wish it will be easier to understand because we already use this in our previous topics

  • There we saw that that this behave like something wired , but trust me it is not wired it is beautiful and effective when you will understand the this keyword properly you will also think that.
  • This means a context , which context we are in , which context we are use this keyword, if we understand the context then we will understand the this keyword easily.
  • In above example we saw that we use call method and we used a different object and then this refer that object later when we use apply method and we use same object but another time then it refer that object again… it means the original context will not effected while using this keyword but we can do our work easily

6. Using of Async Await

I will try to describe in easier way that what async and await is. Async means asynchronous and await means wait.. yes that’s simple as that.

  • Now let’s explore a little bit . when we declare a function and we try to do something with that function , for being single threaded javascipt stop and doing that function’s work not matter how much time it takes.
  • After finish it continue, that’s why we need asynchronous function. means when we declare a function async that means do this work but not stop if you need you can do other work.
  • Then we use await inside the function and say hey wait until i get this. after i get this data you can proceed again.

7. Find Largest Value of an Array

At first we declare a array and then a initial max number.

  • Then we make a for loop for iterating our array because if we want to figure our the maximum number we need to check all the number.
  • Then we check a condition inside the for loop that if that particular element is bigger than the max number then go to the if block rather than ignore it.
  • Inside if block we do what is … as it comes inside the if block that means it it bigger than max number and we assign that number to max number.

8. Sum of All Number in an Array

well it is easy to find the sum of the whole array

  • First we declare a number array and a sum variable and set that variable initial value is 0.
  • After that again we need a for loop for iterating the whole array and that’s the way how we can find whole array’s sum.
  • Then we do a simple trick inside the for loop that we just add the new element value with the previous value of sum. every iteration the value of sum getting update and that’s how we get the sum

9. Remove duplicate Item from an Array

For example , imagine we have an array of number and we need to find out either this array have any duplicate value or not

  • If this array have any duplicate value then we have to remove it and have to return a new fresh array without duplicate value .
  • As we do before , we do here as well , we declare an array and a newArray without anything.
  • And using a for loop we get a single element and after getting the element we check a condition that element is already includes in this array or not if includes then ignore if not… then push it to the array

10. how to Do reverse a String

we can do reverse a string in many ways . but i do something not similar like other .

  • For reverse the array i think in reverse also. i do what is … first declare a string and a empty reverse string variable.
  • Then do a for loop, not a usual one. i do this for loop in reverse that i can find my result in reverse.
  • Then add every single word to that reveseAnthem string and that’s it

Currently I’m working with M E R N stack. I love to learn new technology and explore them. I’m a simply simple person with lots of interests.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store