12 Interview Questions for Javascript Developer

Share this:

This post is on 11 questions for junior developers out there and for those who are looking for or having an interview.

Follow me on twitter where I will be posting cool and short programming codes on this quarantine.

Go and read !!! It’s always good to learn !!!


1) How to copy or clone an array?

In the old way, we can copy an array with a slice().

In a new way i.e after ES6, we can copy array with the spread operator

2) Why can’t we use = to copy an array like (new_variable = existing_array) ?

Because an array is a reference value in javascript. When we write newarray = oldarray, we don’t create a new array rather it’s a reference that points to the same memory location.

3)How do you check if a number is of number type or not in JS?

Remember that typeof variable ===’number’ doesn’t guarantee that variable is number because typeof NaN is also a number.

4) What is the output of +‘12’?

The result is number 12 of type number because the unary operator tries to convert all strings, boolean and null to number.

More example,

It’s also similar to unary + operator

If the interviewer is freak, the output of code below can be asked:

What does this return?

Answer is true

5)What is the output?

The answer is 9.

6) Different ways to copy an object into another?

copy mainobj object into copyobj

But, this is also a shallow copy.
I don’t know if there is another way, for deep copying or cloning I use stringify.

7) How well you know about the call( ), apply( ) and bind( ) in JS?

It really needs more than one para to explain so I am leaving this up to you to learn about the call, apply and bind if you don’t know.

I am soon writing an article on binding in JS in the easiest and detailed way possible in my coming article. It is a favorite topic that let’s the interviewer learn your level of knowledge in JS.

Subscribe, so that I could notify you when I write the article on that and many more interesting articles.

8) Write a code to format the array1 into array2.

and get an output as:

There are a lot of ways to this. I am going to use map() to this array.

9)Create a function filtername() with the first parameter array and second parameter search query.

Condition: It should return an array with elements of name array which has ‘om’ in it.
Required output: [‘Tommy’, ‘Romanu’, ‘Omar’]

10)How do you clone a JSON object?

My answer is stringify. I don’t know if there is another way. Comment your way of doing.

11) What is the result of this code below? write your answer with an explanation.

The result will be 11.

Explanation: If you redeclare variable (var ) in javascript, it does not lose the value because of Hoisting.


To learn more about this, google variable hoisting in javascript.

12) What is the difference between ?=, ?! and ?: expressions in regex?

The difference between ?= and ?! is that former is a positive lookahead mean that regex must be matched while the latter one is negative lookahead means that regex must not be matched. ?: expression is non-capturing group means that regex inside the parentheses should be matched but should be excluded from the entire match.

Thanks for reading.
Take Care and Stay Safe. Help others in need.
Bye !!! See you soon 😀


Related posts

Leave a Reply