Sorry for the generic question. I have searched all over and found so many threads similar to this, however not one that answers my specific question - perhaps because the term I'm looking for doesn't even exist.
var a = "Hello World"; a.replace("Hello", "Goodbye"); console.log(a) // Logs "Hello World"
The reason is because
replace does not modify
a, as strings are immutable in JavaSript. Becuase it returns a string, you'd need to do something like...
var a = "Hello World"; a = a.replace("Hello", "Goodbye"); console.log(a); // Logs "Goodbye World"
reverse(), as it modifies whatever calls it. For example:
var fruits = ["Apples", "Oranges", "Bananas"]; fruits.reverse(); console.log(fruits) // ["Bananas", "Oranges", "Apples"]
When my friend asked me why his
replace wasn't working, I realized I was reaching for a word that I don't know (as far as I'm aware)...
"You have to set the string to "string dot replace", because the replace function is ________."
You don't need to set an array equal to "array dot reverse", because reverse is ________."
I'm familiar with prototype functions though I don't believe that's the word I'm looking for. Can anyone help me fill in these blanks?