Junior Garcia
Junior Garcia@jrgarciadev

Top JavaScript Interview Questions

A selection of crucial JavaScript interview topics to test your skills. Prepare for your next interview with these top questions, designed to evaluate your knowledge and problem-solving abilities.

var output = (function(x) { delete x; return x; })(0); console.log(output);
Answer

The output will be 0. The delete operator is used to remove properties from objects. Here, x is a local variable, not an object property, so the delete operator has no effect on it.

var x = 1; var output = (function() { delete x; return x; })(); console.log(output);
Answer

The output will be 1. The delete operator is used to remove properties from objects. Here, x is a global variable of type number, not an object property, so the delete operator has no effect on it.

var x = { foo : 1 }; var output = (function() { delete x.foo; return x.foo; })(); console.log(output);
Answer

The output will be undefined. The delete operator removes the foo property from the x object. After deletion, x.foo no longer exists, so it returns undefined.

Answer

You can check if an object is an array using several methods:

  1. Using Array.isArray:
Array.isArray(arrayList);
  1. Using Object.prototype.toString:
if(Object.prototype.toString.call(arrayList) === '[object Array]') { console.log('Array!'); }
  1. Using jQuery (if available):
if($.isArray(arrayList)) { console.log('Array'); } else { console.log('Not an array'); }
Page 1 of 3