Javascript Certification Practice Test

Question: 1 / 400

Which of the following statements is true of the substr() method?

It splits a string into an array

It takes the starting index and the number of characters to extract

The statement that the substr() method takes the starting index and the number of characters to extract is indeed true. The substr() method is designed to extract a substring from a given string based on the parameters provided.

When using substr(), the first parameter specifies the index at which to start the extraction. The second parameter denotes the number of characters to retrieve from that starting position. For example, if you have a string "Hello, World!" and you call `substr(7, 5)`, it will return the substring “World” because it starts at index 7 (the character is "W") and extracts 5 characters from that position.

This method does not modify the original string it is called on; instead, it creates and returns a new string based on the specified parameters. This aspect distinguishes it from other string manipulation methods that may alter the original string.

In contrast, the other options misrepresent the functionality of substr(). The method does not split a string into an array, nor does it alter the original string or guarantee a modified string return type. It strictly focuses on extracting a specific substring based on the given start index and length.

Get further explanation with Examzify DeepDiveBeta

It alters the original string

It returns a modified string

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy