var newVar = myVariable.replace("Sunday','Monday");
In this case, myVariable will continue to contain “Today is Sunday” but newVar will contain “Today is Monday”. The following task creates a variable and assigns text to it, replaces that text with new text, and then displays the results in a browser:
1. Open a new HTML document in your preferred HTML or text editor.
2. Create the body of the document with opening and closing body tags:
3. Insert a script block in the body of the document:
4. Create a variable named FirstVariable and assign the value “Hello there” to it:
var FirstVariable = "Hello there";
5. Create a second variable named SecondVariable and assign the results of replacing “there” with “Ecomputernotes” to it:
var SecondVariable = FirstVariable.replace("there","ecomputernotes");
Save the file and close it.
8. Open the file in a browser. You should see the text “Hello Ecomputernotes” displayed in the browser as in Figure