Q. What will be the value of x?

Code:
let x = '2' * '3';
  • (A) '6'
  • (B) 6
  • (C) NaN
  • (D) 23
πŸ’¬ Discuss
βœ… Correct Answer: (B) 6
Explanation: Multiplication forces numeric conversion, so '2' * '3' = 6.

Q. What does 'this' refer to in a regular function?

  • (A) Global object
  • (B) Window object in browser
  • (C) Object that called the function
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of the above
Explanation: 'this' can refer to different things depending on the context.

Q. What will the following return?

Code:
typeof Infinity;
  • (A) number
  • (B) infinity
  • (C) undefined
  • (D) object
πŸ’¬ Discuss
βœ… Correct Answer: (A) number
Explanation: Infinity is of type number in JavaScript.

Q. Which of the following is used to create a new Promise?

Code:
let p = new Promise((resolve, reject) => {});
  • (A) Correct syntax
  • (B) Incorrect syntax
  • (C) Deprecated
  • (D) Throws error
πŸ’¬ Discuss
βœ… Correct Answer: (A) Correct syntax
Explanation: This is the correct way to create a new Promise.

Q. What will be logged?

Code:
console.log(typeof undefined === typeof null);
  • (A) true
  • (B) false
  • (C) undefined
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) false
Explanation: typeof undefined is 'undefined', typeof null is 'object'.

Q. What does '===' operator check?

  • (A) Only value
  • (B) Only type
  • (C) Value and type
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) Value and type
Explanation: === checks both value and type without coercion.

Q. What is the default value of 'this' in a JavaScript class method?

  • (A) window
  • (B) undefined
  • (C) the class instance
  • (D) null
πŸ’¬ Discuss
βœ… Correct Answer: (C) the class instance
Explanation: In class methods, 'this' refers to the class instance.

Q. What will be the output?

Code:
console.log(1 + '1' - 1);
  • (A) 10
  • (B) 11
  • (C) 1
  • (D) NaN
πŸ’¬ Discuss
βœ… Correct Answer: (A) 10
Explanation: 1 + '1' = '11'; '11' - 1 = 10 due to coercion.

Q. Which of the following is a correct way to declare an arrow function?

  • (A) function => {}
  • (B) () -> {}
  • (C) () => {}
  • (D) => {}
πŸ’¬ Discuss
βœ… Correct Answer: (C) () => {}
Explanation: The arrow function syntax is () => {}.

Q. What is hoisting in JavaScript?

  • (A) Declaring variables at the top
  • (B) Using let and const only
  • (C) JavaScript's default behavior of moving declarations to the top
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) JavaScript's default behavior of moving declarations to the top
Explanation: Hoisting means variable/function declarations are moved to the top.