43.9k views
3 votes
Assume courseTitle ="Principles in Information Technology and Computation";

What does the following JavaScript statement do?

var something = courseTitle.search('o');

It finds all o's and save them to variable something.

It saves the position of the first occurrence of "o" to variable something.

It saves the position of the last occurrence of "o" to variable something.

It will save a true or false to something depends on whether there is an 'o' in courseTitle.

User Alex Wolf
by
6.3k points

1 Answer

3 votes

Answer:

It saves the position of the first occurrence of "o" to variable something.

Step-by-step explanation:

The search() method in javascript searches the expression or the string and returns the position of it's first occurrence and if not found it returns -1.

So in the code given above it will search for character o and returns the position of it's first occurrence that is 16 and if there were no o in the string then it would have returned -1.

User Arun Pandian M
by
5.0k points