Download - 21 Essential JavaScript Interview Questions
![Page 1: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/1.jpg)
21 Essential JavaScript Interview Questions
by Codementor Nishant Kumar
![Page 2: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/2.jpg)
What is the difference between undefined and not defined in JavaScript?
Question 1:
![Page 3: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/3.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/4.jpg)
What is the drawback of creating true private methods in JavaScript?
Question 3:
![Page 5: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/5.jpg)
What is a “closure” in JavaScript? Provide an example.
Question 4:
![Page 6: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/6.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/7.jpg)
How do you empty an array in JavaScript?
Question 6:
![Page 8: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/8.jpg)
How do you check if an object is an array or not?
Question 7:
![Page 9: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/9.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/10.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/11.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/12.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/13.jpg)
What is undefined x 1 in JavaScript?
Question 12:
![Page 14: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/14.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/15.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/16.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/17.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/18.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/19.jpg)
What is function hoisting in JavaScript?
Question 18:
![Page 20: 21 Essential JavaScript Interview Questions](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/20.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/21.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/22.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021921/58f9a8be760da3da068b6755/html5/thumbnails/23.jpg)
Did you know how to answer all 21 questions?
Feel free to check your answers & view detailed explanations here!