Jinu Joseph Daniel
Jinu Joseph Daniel

Reputation: 6291

Javascript String.replace() ,ambiguous results

See my code

<html>
<body>

<script type="text/javascript">

var str="Visit Microsoft!";

document.write( str = str.replace("",'ss'));

</script>
</body>
</html>

The output is

 ssVisit Microsoft!

Why is it happening.?

Upvotes: 2

Views: 241

Answers (1)

Pramod
Pramod

Reputation: 36

This is correct because every string begins with an empty string. See below post for more info:

Why does "abcd".StartsWith("") return true?

Upvotes: 2

Related Questions