Q. Which statement is true for arrow functions?

  • (A) They bind their own 'this'
  • (B) They use lexical 'this'
  • (C) They are block-scoped
  • (D) They must use function keyword
πŸ’¬ Discuss
βœ… Correct Answer: (B) They use lexical 'this'
Explanation: Arrow functions do not bind their own this; they inherit from parent.

Q. What will be logged?

Code:
let arr = [1, 2, 3];
arr.length = 1;
console.log(arr);
  • (A) [1]
  • (B) [1, 2, 3]
  • (C) []
  • (D) [1, 2]
πŸ’¬ Discuss
βœ… Correct Answer: (A) [1]
Explanation: Setting length to 1 truncates the array to one element.

Q. What is the result of the following?

Code:
console.log(typeof NaN);
  • (A) NaN
  • (B) number
  • (C) undefined
  • (D) object
πŸ’¬ Discuss
βœ… Correct Answer: (B) number
Explanation: NaN stands for Not-a-Number but its type is 'number'.

Q. What will this expression return?

Code:
Boolean([]);
  • (A) true
  • (B) false
  • (C) undefined
  • (D) null
πŸ’¬ Discuss
βœ… Correct Answer: (A) true
Explanation: An empty array is a truthy value in JavaScript.

Q. Which is not a valid JavaScript data type?

  • (A) Undefined
  • (B) Boolean
  • (C) Float
  • (D) Symbol
πŸ’¬ Discuss
βœ… Correct Answer: (C) Float
Explanation: JavaScript has no distinct 'float' type, only 'number'.

Q. What is the output?

Code:
console.log('2' + 2 - 2);
  • (A) 22
  • (B) 2
  • (C) NaN
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (B) 2
Explanation: '2' + 2 = '22'; '22' - 2 = 20.

Q. What does the following return?

Code:
[] == ![];
  • (A) true
  • (B) false
  • (C) undefined
  • (D) TypeError
πŸ’¬ Discuss
βœ… Correct Answer: (A) true
Explanation: [] is truthy, ![] is false. [] == false is true due to coercion.

Q. Which method is used to convert an object to JSON string?

  • (A) JSON.parse()
  • (B) JSON.stringify()
  • (C) toString()
  • (D) parseJSON()
πŸ’¬ Discuss
βœ… Correct Answer: (B) JSON.stringify()
Explanation: JSON.stringify() converts an object into a JSON string.

Q. Which array method returns a new array with only truthy values?

  • (A) filter()
  • (B) map()
  • (C) reduce()
  • (D) forEach()
πŸ’¬ Discuss
βœ… Correct Answer: (A) filter()
Explanation: filter() creates a new array with elements that pass a test.

Q. Which of these is a valid JavaScript variable name?

  • (A) 1value
  • (B) $value
  • (C) var
  • (D) -value
πŸ’¬ Discuss
βœ… Correct Answer: (B) $value
Explanation: Variable names can begin with $ or _ but not numbers or reserved keywords.