Question discussion

What is the output of the following JavaScript code?console.log([..."abc"].reverse().join(""), typeof NaN, [1, 2, 3].indexOf(4));

1509Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following JavaScript code?

console.log([..."abc"].reverse().join(""), typeof NaN, [1, 2, 3].indexOf(4));
  • Aabc number 0
  • Bcba NaN -1
  • Ccba number undefined
  • Dcba number -1
Correct answer: D

Explanation

The string is spread into letters, reversed and joined to "cba"; typeof NaN is "number"; indexOf returns −1 when the element is absent.

Discussion 0

Nobody has replied yet. Start the discussion!