JavaScript > Introduction

Statements in JavaScript

How to write JavaScript statement?


Statements

In HTML, JavaScript statements are commands to the browsers. Each JavaScript statement should be terminated using “;” (semi colon) character. JavaScript code can also be grouped using opening braces “{“ and closing curly braces “}”. Let's see some examples related to JavaScript statements.

Writing "TechFunda" inside an  HTML element with ID

<p id="myId"></p>

<script>
    document.getElementById("myId").innerHTML = "TechFunda";
</script>

In the above code snippet we have given document.getElementById in the script code, which returns the element with the Id "myId" in the HTML page.

OUTPUT

Program with Semi colon's, open & closed braces

Every statement should be ends with semi colon ';' and every JavaScript function can start and ends with open '{' and close '}' curly braces.

<script>
  var firstName = "Shanti Shen";

  function GetMyName()
  {
    return firstName;
  }

  // call the function declare above
  var name = GetMyName();

  alert(name);
</script>

JavaScript Statements

 Views: 9062 | Post Order: 1



Write for us






Hosting Recommendations