0 votes
in JavaScript by
What's the output?
console.log('I want pizza'[0]);
  • A: """
  • B: "I"
  • C: SyntaxError
  • D: undefined

1 Answer

0 votes
by

Answer: B

In order to get a character at a specific index of a string, you can use bracket notation. The first character in the string has index 0, and so on. In this case, we want to get the element with index 0, the character "I', which gets logged.

Note that this method is not supported in IE7 and below. In that case, use .charAt().

Related questions

0 votes
asked Mar 13 in JavaScript by DavidAnderson
0 votes
asked Mar 10 in JavaScript by DavidAnderson
...