Javascript: Variables

This entry is part 6 of 27 in the series Javascript Tutorial

<!DOCTYPE html>
 <h1>Second JavaScript Program</h1>
 <p>Click the button to change the sentence</p>
 <p id="second">Second Program</p>
 <button type="button" onclick="myFunction()">Try it</button>
    function myFunction() {
          var new_string = "This is my second Javascript program";
          document.getElementById("second").innerHTML = new_string;


In this example, we introduce a variable called new_string.

var new_string = "This is my second Javascript program"

We first assign a sentence to new_string, update the paragraph with id=”second” with new_string.

document.getElementById("second").innerHTML = new_string;
Series Navigation<< Javascript: First example explanations
Javascript: Basic HTML tags >>

Leave a comment

Leave a Reply