30 Essential JavaScript Interview Questions You Should Know

Let’s learn some JavaScript questions which you should know before you appear in your interview. First of all let’s see what is JavaScript?

JavaScript is a high-level, versatile programming language widely used for creating interactive and dynamic content on websites. It is primarily a client-side language that runs in web browsers to enhance user interfaces and experiences, but it can also be used on the server side with environments like Node.js.

Javascript inteview questions

Here are some JavaScript MCQ questions with answers that will help you to prepare for your next interview.

Multiple Choice Questions with Answers

Q1. Which of the following is not a reserved word in JavaScript?

  • interface
  • throws
  • program
  • short
View Answer

program


Q2. In JavaScript the x===y statement implies that

  • Both x and y are equal in value, type and reference address
  • Both are x and y are equal in value only
  • Both are equal in the value and data type
  • Both are not same at all
View Answer

Both are equal in the value and data type


Q3. What will typeof NaN return?

  • number
  • NaN
  • undefined
  • object
View Answer

number


Q4. What is the output of the following code?

console.log(typeof null);
  • null
  • undefined
  • object
  • number
View Answer

object


Q5. What will NaN === NaN evaluate to in JavaScript?

  • True
  • False
  • Undefined
  • None of the above
View Answer

False


Q6. Which of the following is not a valid JavaScript variable name?

  • _myVar
  • my-var
  • $myVar
  • myVar1
View Answer

my-var


Q7. What is the output of the following code?

function test() {
    console.log(this);
}
test();
  • undefined
  • null
  • Window object (in browsers)
  • test function
View Answer

Window object (in browsers)


Q8. Which of the following method is used to merge two arrays into one?

  • arr1 + arr2
  • arr1.concat(arr2)
  • arr1.add(arr2)
  • arr1.merge(arr2)
View Answer

arr1.concat(arr2)


Q9. What is the use of Promise.all method?

  • To run multiple promises sequentially
  • To wait until all promises are either resolved or rejected
  • To run multiple promises and return the result of the first resolved promise
  • To handle the first rejected promise only
View Answer

To wait until all promises are either resolved or rejected


Q10. What will be the output of the following code?

let a = [1, 2, 3];
let b = a;
b.push(4);
console.log(a);
  • [1, 2, 3]
  • [1, 2, 3, 4]
  • undefined
  • error
View Answer

[1, 2, 3, 4]


Q11. What is the purpose of the bind method in JavaScript?

  • To call a function with a specified this context
  • To create a new function with a specified this context and arguments
  • To call a function immediately with a specified this context
  • To add properties to an object
View Answer

To create a new function with a specified this context and arguments


Q12. What does the async keyword do when applied to a function?

  • It turns the function into a generator function
  • It makes the function execute synchronously
  • It allows the function to return a promise and to use await within it
  • It allows the function to be executed only in an async context
View Answer

It allows the function to return a promise and to use await within it


Q13. What will be the output of the following code?

console.log("5" + 3);
  • 8
  • 53
  • error
  • undefined
View Answer

53


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

let a = 10;
(function() {
    console.log(a);
    let a = 20;
})();
  • 10
  • 20
  • undefined
  • ReferenceError
View Answer

ReferenceError


Q15. What is the output of the following code?

const obj = {
    a: 1,
    b: 2,
    c: 3
};
console.log(Object.keys(obj).length);
  • 1
  • 2
  • 3
  • 4
View Answer

3


Q16. Which of the following is true about the setTimeout function?

  • It immediately executes the specified function
  • It delays the execution of the specified function until the browser is idle
  • It executes the specified function after the given delay
  • It repeatedly executes the specified function at fixed intervals
View Answer

It executes the specified function after the given delay


Q17. What will be the output of the following code?

function foo() {
    return {
        bar: "hello"
    };
}
console.log(foo().bar);
  • hello
  • undefined
  • null
  • Error
View Answer

hello


Q18. Which of the following statements is correct about async functions?

  • async functions return a promise
  • async functions must contain an await statement
  • async functions cannot be used as constructors
  • Both A and C
View Answer

Both A and C


Q19. What is the main purpose of the Event Loop in JavaScript?

  • To execute synchronous code
  • To handle asynchronous callbacks
  • To manage memory allocation
  • To parse JavaScript code
View Answer

To handle asynchronous callbacks


Q20. What is the output of the following code?

const a = [];
const b = a;
b.push(1);
console.log(a === b);
  • false
  • true
  • undefined
  • Error
View Answer

true


Q21. Which of the following is not a primitive data type in JavaScript?

  • String
  • Number
  • Boolean
  • Object
View Answer

Object


Q22. What will be the output of the following code?

var a = [1, 2, 3];
a[10] = 99;
console.log(a.length);
  • 3
  • 4
  • 11
  • 10
View Answer

11


Q23. What does the isNaN() function do?

  • Checks if a value is null
  • Checks if a value is not a number
  • Checks if a value is a number
  • Checks if a value is NaN
View Answer

Checks if a value is not a number


Q24. What will be the output of the following code?

function foo() {
    return
    {
        bar: "hello"
    };
}
console.log(foo());
  • undefined
  • { bar: “hello” }
  • null
  • Throws a syntax error
View Answer

undefined


Q25. What will be the output of the following code?

let a = 1;
let b = 2;
[a, b] = [b, a];
console.log(a, b);
  • 1 2
  • 2 1
  • undefined undefined
  • 1 undefined
View Answer

2 1


Q26. Which of the following number object function returns the value of the number?

  • toString()
  • valueOf()
  • toLocaleString()
  • toValue()
View Answer

valueOf()



Q27. Which one of the following operator is used to check weather a specific property exists or not?

  • exists
  • within
  • includes
  • in
View Answer

in



Q28. Which of the following is a ternary operator

  • :
  • ?
  • ||
  • |
View Answer

?




Q29. Which one of the following is not considered as “statement” in the JavaScript?

  • use strict
  • debugger
  • if
  • with
View Answer

use strict




Q30. In JavaScript, what kind of scoping is used?

  • Literal scoping
  • Segmental scoping
  • Lexical scoping
  • Default scoping
View Answer

Lexical Scoping