JavaScript > Introduction

Statements in JavaScript

How to write JavaScript statement?


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>

    document.getElementById("myId").innerHTML = "TechFunda";

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.


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.

  var firstName = "Shanti Shen";

  function GetMyName()
    return firstName;

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


JavaScript Statements

 Views: 9132 | Post Order: 1

Write for us

Hosting Recommendations