23
21 Essential JavaScript Interview Questions by Codementor Nishant Kumar

21 Essential JavaScript Interview Questions

Embed Size (px)

Citation preview

Page 1: 21 Essential JavaScript Interview Questions

21 Essential JavaScript Interview Questions

by Codementor Nishant Kumar

Page 2: 21 Essential JavaScript Interview Questions

What is the difference between undefined and not defined in JavaScript?

Question 1:

Page 3: 21 Essential JavaScript Interview Questions

What will be the output of the code below?

var y = 1;

if (function f(){}) {

y += typeof f;

}

console.log(y);

Question 2:

Page 4: 21 Essential JavaScript Interview Questions

What is the drawback of creating true private methods in JavaScript?

Question 3:

Page 5: 21 Essential JavaScript Interview Questions

What is a “closure” in JavaScript? Provide an example.

Question 4:

Page 6: 21 Essential JavaScript Interview Questions

Write a mul function which will produce the following outputs when invoked:

javascript console.log(mul(2)(3)(4)); // output : 24 console.log(mul(4)(3)(4)); // output : 48

Question 5:

Page 7: 21 Essential JavaScript Interview Questions

How do you empty an array in JavaScript?

Question 6:

Page 8: 21 Essential JavaScript Interview Questions

How do you check if an object is an array or not?

Question 7:

Page 9: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

var output = (function(x){

delete x;

return x;

})(0);

console.log(output);

Question 8:

Page 10: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

var x = 1;

var output = (function(){

delete x;

return x;

})();

console.log(output);

Question 9:

Page 11: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

var x = { foo : 1};

var output = (function(){

delete x.foo;

return x.foo;

})();

console.log(output);

Question 10:

Page 12: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

var x = { foo : 1};

var Employee = {

company: 'xyz'

}

var emp1 = Object.create(Employee);

delete emp1.company

console.log(emp1.company);

Question 11:

Page 13: 21 Essential JavaScript Interview Questions

What is undefined x 1 in JavaScript?

Question 12:

Page 14: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

Question 13:

var trees = ["xyz","xxxx","test","ryan","apple"];

delete trees[3];

console.log(trees.length);

Page 15: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

var bar = true;

console.log(bar + 0);

console.log(bar + "xyz");

console.log(bar + true);

console.log(bar + false);

Question 14:

Page 16: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

var x = { foo : 1};

var z = 1, y = z = typeof y;

console.log(y);

Question 15:

Page 17: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

// NFE (Named Function Expression

var foo = function bar(){ return 12; };

typeof bar();

Question 16:

Page 18: 21 Essential JavaScript Interview Questions

What is the difference between the following two functions?

Question 17:

var foo = function(){ // Some code };

function bar(){ // Some code };

Page 19: 21 Essential JavaScript Interview Questions

What is function hoisting in JavaScript?

Question 18:

Page 20: 21 Essential JavaScript Interview Questions

What will be the output of the following code?

Question 19:

var salary = "1000$";

(function () { console.log("Original salary was " + salary);

var salary = "5000$";

console.log("My New Salary " + salary); })();

Page 21: 21 Essential JavaScript Interview Questions

What is the instanceof operator in JavaScript?

What would be the output of the code below?

Question 20:

function foo(){ return foo; }new foo() instanceof foo;

Page 22: 21 Essential JavaScript Interview Questions

If we have a JavaScript associative array

Question 21:

var counterArray = { A : 3, B : 4};counterArray["C"] = 1;

How can we calculate length of its counterArray?

Page 23: 21 Essential JavaScript Interview Questions

Did you know how to answer all 21 questions?

Feel free to check your answers & view detailed explanations here!