Interview questions and answers in javascript

Here is the list of most frequently asked interview questions

Explain Object creation patterns

  • - literal
  • - new Object()
  • - Object.create()
  • - Constructors

How to access all properties and methods of object

for(var key in localStorage) {
    console.log (localStorage[key]);

Explain closures

Using closures, we can hide inner details of function and also create public and private methods A pattern often used in place of an object with a single method, is to take advantage of closure by creating a function that returns an inner function. That inner function will have access to any variables defined in the outer function, without ever exposing those variables to a larger scope. all public methods should be returned in outer function and private methods should not be returned. public methods will access private variables and methods using closure concept.

Explain Prototypes


var parent = { property: 2 };

//here child object is created using parent's prototype so child will inherit properties of parent
var child = Object.create(parent);  
console.log(; = 3;


difference between == and ===

=== check the equality of value and type. e.g "2"==2 is true but "2"===2 is false.

output of 1+2+"3" and "1"+2+3

1+2+"3" and "1"+2+3 will have different output - 33 and 123 respectively.

undefined vs null

All unassigned variables will have a default value of undefined. null is a object. We can delete the object reference by setting variable to null.

delete element in array

//delete an element in array

function removeAllElements(array, elem) {
    var index = array.indexOf(elem);
    while (index > -1) {
        array.splice(index, 1);
        index = array.indexOf(elem);

How to get browser and OS details

Navigator.appVersion and Navigator.platform

How to format the Date

new Date().getDate(), getMonth(), getFullYear()

How to write multi line code

We can write multi line code by using \


void(0) means do nothing. Even default action is not done. e.g. clicking on link will not open the new page.

Difference between call, apply and bind

Explain event bubbling

unescape() and escape() vs decodeURI() and encodeURI()

How to delete the object's property

delete keyword is used to delete the property and value.

//delete an element in array

let car= {price:20, model:"Honda"};
delete car.price;

Difference between Set and Map and WeakSet and WeakMap

Best Practises

Real life examples and challenges

Complex problems, Simple Solutions