JavaScript interview questions and answers

In all sorts of Web development position's interview Javascript questions are very obvious. The front-end Web developer position requires Javascript skills in grater way. Javascript skills are in general very useful in many ways. Javascript is the core of client-side script. So, the knowledge of Javascript is a must. Following are some Javascript interview questions that might help passionate Javascript developers.

Q1. What will be the value of Boolean("undefined")?

a. true
b. false
c. undefined
d. Uncaught SyntaxError: Unexpected token ILLEGAL

Answer of Q1: 

a. true 


Q2. Is it possible to write file in the file system using Javascript?

a. Yes
b. No
c. Text files are possible
d. Executable files are possible

Answer of Q2: 

b. No


Q3. Is it possible to set the value of an file type input element using Javascript?

a. No
b. Yes
c. Small size files are allowed
d. Only images are allowed

Answer of Q3: 

a. No


Q4. What will return this function parseInt("010", 8);?

a. 8
b. 10
c. 0
d. 2

Answer of Q4:

a. 8


Q5. What this function will return isFinite(NaN);?

a. undefined
b. null
c. true
d. false

Answer of Q5:

d. false


Q6. What will be the output of the following code segment?

function add() {
  console.log(typeof arguments)
};
add();
a. Object
b. Array
c. Number
d. Uncaught SyntaxError: Unexpected token ILLEGAL

Answer of Q6:

a. Object


Q7. What will be the output of the following code segment?

var num = 01; 
var str = '4';
console.log(num + str);
a. 5
b. 4
c. 1
d. 14

Answer of Q7:

d. 14


Q8. What will be the output of the following code segment?

var num = 01; 
var str = '4';
console.log(num + +str);
a. 5
b. 4
c. 1
d. 14

Answer of Q8:

a. 5


Q9. What is the meaning of this expression var userAge = age || getAge();

a. It will do an OR operation with the return value of getAge function and the value of age variable and then it will assign to userAge variable
b. If the variable age is true then it will assign that to userAge otherwise it will assign the return value of getAge function
c. It will always assign the variable age's value to userAge variable
d. It will always assign the function getAge's return value to userAge variable

Answer of Q9:

b. If the variable age is true then it will assign that to userAge otherwise it will assign the return value of getAge function


Q10. In the global context what will be the value of this console.log(this.document == window)?

a. true
b. false
c. undefined this
d. Uncaught ComparisonError: Unexpected token ILLEGAL

Answer of Q10:

b. false


Q11. What this window.title will return?

a. Title of the document
b. Object
c. Undefined
d. Uncaught AccessError: Unexpected attempt to access Object

Answer of Q11:

c. undefined


Q12. In Javascript Functions are not?

a. Object
b. Subprogram
c. Procedures
d. All of the above

Answer of Q12:

c. Procedures 


Q13. How many arguments a Javascript function can have?

a. 127
b. 255
c. 511
d. unlimited

Answer of Q13:

b. 255 


Q14. What will be the output of the following code segment?

var add = function summation(num1, num2){
  return num1 + num2;
}
console.log(summation(5, 10));
a. 15
b. Uncaught ReferenceError: summation is not defined
c. 105
d. num1 + num2

Answer of Q14:

b. Uncaught ReferenceError: summation is not defined


Q15. What will be the output of the following code segment?

function closureInLoop() {
  for(var i = 0; i < 3 ;i++) {
    setTimeout(function(){
      console.log(i)
    })
  }
}
closureInLoop();
a. 012
b. 000
c. 333
d. 222

Answer of Q15:

c. 333 


Q16. What will be the output of the following code segment?

function increment(num) {
  (function(){
    console.log(num);
  })();
  ++num;  
}
increment(100);
a. 100
b. 101
c. 1001
d. NULL

Answer of Q16:

a. 100


Q17. Who is the creator of Javascript and which company?

a. Brendan Eich & Netscape
b. Brendan Eich & Mozilla
c. Brendan Eich & AOL
d. None of the above

Answer of Q17:

a. Brendan Eich & Netscape


Q18. What will be the output of the following code snippet?

function add(){
  var arrays = [10,20,30,40];
  arrays.reduce(function (total, num) {
    return total + num;
  })
}
console.log(add());
a. 100
b. 10203040
c. undefined
d. null

Answer of Q18:

c. undefined


Q19. What will be the output of the following code snippet?

function multiplication(a, b) {
  return a * b;
}
console.log(multiplication.apply(undefined,[10, 20]));
a. 200
b. Fatal error: undefined is declared
c. 0
d. null

Answer of Q19:

a. 200


Q20. What will be the scope of this if it is called through Javascript's call() method?

var showMethod = function () {
  console.log(this);
}.call({});
a. Window object
b. Fatal error: call method with empty scope
c. Object {}
d. undefined

Answer of Q20:

c. Object {}


Q21. What will be the value of this if it is bind with document title?

var func = function showMethod(){
  console.log(this);
}.bind(this.document.title);
func();
a. String
b. Fatal error: bind must call with object
c. Object
d. undefined

Answer of Q21:

a. String


Q22. What will be the output of the following code when it is called after storing it to a variable?

var popstar = 'Justin Bieber';
var obj = {
  popstar: 'Taylor Swift',
  getPopstarName: function() {
    return this.popstar;
  }
};
var temp = obj.getPopstarName;
console.log(temp());
a. Justin Bieber
b. Taylor Swift
c. Object
d. undefined

Answer of Q22:

a. Justin Bieber


Q23. What will be the output of the global variable after calling the doSomething() function?

var num;
function doSomething(){
  console.log(num);
  num = function printValue(){
    return 2;
  }();
}
doSomething();
a. 2
b. Uncaught ReferenceError: printValue is not defined
c. false
d. undefined

Answer of Q23:

d. undefined


Q24. What will be the output if the returned object is accessed in following way?

function getObject(){
  return {
    Barcelona : "Leo Messi",
    Real Madrid : "Cristiano Ronaldo"
  };
}
console.log(getObject().Barcelona);
a. Leo Messi
b. Uncaught SyntaxError: Unexpected identifier
c. Uncaught ReferenceError: Barcelona is not defined
d. undefined

Answer of Q24:

b. Uncaught SyntaxError: Unexpected identifier


Q25. What will be the output of the following function call?

function getObject(){
  return
  {
    date:parseInt('15th June')
  };
}

console.log(getObject());
a. Object {date: 15}
b. Uncaught SyntaxError: Unexpected identifier
c. Uncaught ReferenceError: parseInt is called with invalid string
d. undefined

Answer of Q25:

d. undefined


Q26. What it will return if we compare NaN with another NaN value?

var num = parseInt('Monday 4th July');
console.log(num == NaN);
a. true
b. false
c. Uncaught ReferenceError: parseInt is called with invalid string
d. undefined

Answer of Q26:

b. false


Q27. What it will return if we lookup the 'valueOf' inside an object?

var bestCar = {company: "BMW", model: "BMW i8", year: 2015, country: 'US'};
console.log("valueOf" in bestCar);
a. true
b. false
c. Uncaught ReferenceError: in operator is called with invalid object property
d. undefined

Answer of Q27:

a. true


Comments