Multiple choice technology architecture

JavaScript Function to find the position of a Character in a String Variable? Var x = “[email protected]”;

  1. var atpos = x.charAt(0);

  2. var atpos = x.charAt(‘A’);

  3. var atpos = x.indexOf(“@”);

  4. var atpos = x.indexOf(‘@’);

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

indexOf() returns the starting position of a substring within a string, which is exactly what we need to locate the '@' character. charAt() retrieves the character AT a given index, not the position of a character, so options A and B are backwards. Option D incorrectly uses single quotes around '@' which would cause a syntax error in JavaScript (single quotes work in strings but not as arguments when double quotes are used elsewhere).