Question 10
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log("Hello World".search(/o/), "Hello".search("z"), "a.b".search("."));
- A 4 -1 0 Correct
- B 4 -1 1
- C 7 -1 1
- D 4 0 1
Correct Answer: Option A
search converts a string argument into a regex, so "." means "any character" and matches at index 0 – a classic surprise.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!