Multiple choice technology programming languages


    var str = "This is an Example";
    alert(str.replace("Example", "Error"));     

  1. Example

  2. Error

  3. This is an Example

  4. This is an Error

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

The replace() method finds the first occurrence of 'Example' and replaces it with 'Error', resulting in 'This is an Error'. Note that replace() only replaces the first match unless you use a regex with the global flag.