문제

"ahoj".replace("o")
//=> "ahundefinedj"
"ahoj".replace("q")
//=> "ahoj"

Why is that? How is replace implemented? Is there any way I could see the implementation itself?

도움이 되었습니까?

해결책

Pay attention to what you get.

ah undefined j

Spaces added for emphasis. It replaced o with the second argument... which was undefined.

The second replace does nothing because there is no q to replace.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top