Q. Which keyword is used for inheritance in ES6 classes?

  • (A) extends
  • (B) implements
  • (C) inherits
  • (D) derive
πŸ’¬ Discuss
βœ… Correct Answer: (A) extends
Explanation: extends is used to create a subclass in JavaScript.

Q. What will this output?

Code:
console.log(typeof function(){});
  • (A) object
  • (B) function
  • (C) undefined
  • (D) string
πŸ’¬ Discuss
βœ… Correct Answer: (B) function
Explanation: typeof on any function returns 'function'.

Q. How can you prevent a variable from being reassigned?

  • (A) Use var
  • (B) Use let
  • (C) Use const
  • (D) Use strict
πŸ’¬ Discuss
βœ… Correct Answer: (C) Use const
Explanation: const ensures the variable cannot be reassigned.

Q. What will the following code return?

Code:
let x = 0;
if (x) { console.log('true'); } else { console.log('false'); }
  • (A) true
  • (B) false
  • (C) undefined
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (B) false
Explanation: 0 is falsy, so it prints 'false'.

Q. Which method checks if an array contains a certain value?

  • (A) has()
  • (B) contains()
  • (C) includes()
  • (D) exists()
πŸ’¬ Discuss
βœ… Correct Answer: (C) includes()
Explanation: includes() checks for presence of an element in an array.

Q. What will be the result?

Code:
const obj = {name: 'John'};
delete obj.name;
console.log(obj.name);
  • (A) undefined
  • (B) John
  • (C) null
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) undefined
Explanation: The delete operator removes the property from the object.

Q. What is the default return value of a function with no return statement?

  • (A) null
  • (B) 0
  • (C) undefined
  • (D) false
πŸ’¬ Discuss
βœ… Correct Answer: (C) undefined
Explanation: A function with no return returns undefined.

Q. What will be logged?

Code:
console.log(typeof []);
  • (A) array
  • (B) object
  • (C) undefined
  • (D) list
πŸ’¬ Discuss
βœ… Correct Answer: (B) object
Explanation: Arrays in JavaScript are objects.

Q. Which statement is used to exit a loop early?

  • (A) exit
  • (B) continue
  • (C) stop
  • (D) break
πŸ’¬ Discuss
βœ… Correct Answer: (D) break
Explanation: break exits the loop immediately.

Q. What will be printed?

Code:
let a = [1, 2];
a[10] = 99;
console.log(a.length);
  • (A) 2
  • (B) 11
  • (C) 10
  • (D) 12
πŸ’¬ Discuss
βœ… Correct Answer: (B) 11
Explanation: Setting index 10 makes the array length 11.