Q. Which method is used to handle errors in Promises?

  • (A) catch()
  • (B) then()
  • (C) error()
  • (D) fail()
πŸ’¬ Discuss
βœ… Correct Answer: (A) catch()
Explanation: catch() handles Promise rejections or errors.

Q. What is the purpose of async keyword in JavaScript?

  • (A) To define a function that returns a Promise
  • (B) To pause code execution
  • (C) To define synchronous code
  • (D) To create event loops
πŸ’¬ Discuss
βœ… Correct Answer: (A) To define a function that returns a Promise
Explanation: An async function always returns a Promise.

Q. What is the purpose of the await keyword?

  • (A) To wait for a Promise to resolve
  • (B) To block the main thread
  • (C) To delay function execution
  • (D) To create a loop
πŸ’¬ Discuss
βœ… Correct Answer: (A) To wait for a Promise to resolve
Explanation: await pauses execution until the Promise resolves or rejects.

Q. Which JavaScript feature allows function to access variables from an outer scope?

  • (A) Closure
  • (B) Scope chain
  • (C) Callback
  • (D) Hoisting
πŸ’¬ Discuss
βœ… Correct Answer: (A) Closure
Explanation: Closures give functions access to variables from their outer lexical scope.

Q. Which keyword is used to define a class in JavaScript?

  • (A) class
  • (B) object
  • (C) structure
  • (D) function
πŸ’¬ Discuss
βœ… Correct Answer: (A) class
Explanation: The class keyword is used to define a class in ES6+.

Q. How do you create an instance of a class?

  • (A) new ClassName()
  • (B) create ClassName()
  • (C) object ClassName()
  • (D) instanceof ClassName()
πŸ’¬ Discuss
βœ… Correct Answer: (A) new ClassName()
Explanation: Use the new keyword to create an instance of a class.

Q. Which method is automatically called when a new object is created?

  • (A) constructor
  • (B) init
  • (C) create
  • (D) build
πŸ’¬ Discuss
βœ… Correct Answer: (A) constructor
Explanation: The constructor() method is automatically invoked when an instance is created.

Q. What is lexical scope?

  • (A) Scope determined at compile time based on code structure
  • (B) Scope determined at runtime
  • (C) Scope of a function inside a loop
  • (D) Scope within a class
πŸ’¬ Discuss
βœ… Correct Answer: (A) Scope determined at compile time based on code structure
Explanation: Lexical scope means the scope is determined by the physical placement of code.

Q. What will be the output of: typeof Promise?

  • (A) function
  • (B) object
  • (C) undefined
  • (D) promise
πŸ’¬ Discuss
βœ… Correct Answer: (A) function
Explanation: Promise is a constructor function, so typeof Promise returns 'function'.

Q. What will be the result of await Promise.reject('error') in async function?

  • (A) Unhandled rejection error
  • (B) Syntax error
  • (C) Code continues
  • (D) undefined
πŸ’¬ Discuss
βœ… Correct Answer: (A) Unhandled rejection error
Explanation: The error must be caught or it results in an unhandled rejection.