JavaScript Introduction

JavaScript is a popular scripting language that control the behavior of the webpage using script.

Where to Place JavaScript Code?

You can place your JavaScript code in two places.

Advertisements
  • Inside the HTML document
  • Use an external file for JavaScript and link to HTML document.

JavaScript inside HTML page

<script>
   document.write("Hello world");
<script/>

External JavaScript File

For external JavaScript file, you have to link it to HTML document.

<script src="demo.js"></script>

Output Method in JavaScript

JavaScript programming output method in four different ways. They are listed below.

  • <mark style="background-color:rgba(0, 0, 0, 0);color:#bc1212" class="has-inline-color">document.getElementById(“demo”).innerHTML = ‘hello”;</mark>
  • <mark style="background-color:rgba(0, 0, 0, 0);color:#ba1010" class="has-inline-color">console.log(“Hello”);</mark>
  • <mark style="background-color:rgba(0, 0, 0, 0);color:#b61414" class="has-inline-color">alert(“hello”);</mark>
  • <mark style="background-color:rgba(0, 0, 0, 0);color:#b81414" class="has-inline-color">document.write(“Hello”);</mark>

The first method is using <mark style="background-color:rgba(0, 0, 0, 0);color:#b91515" class="has-inline-color">HTML DOM</mark> and <mark style="background-color:rgba(0, 0, 0, 0);color:#c70d0d" class="has-inline-color">selector API</mark> functions like <mark style="background-color:rgba(0, 0, 0, 0);color:#b01414" class="has-inline-color">getElementById</mark>, etc.

Advertisements

The second method prints the output to the browser console.

The third method usually used for creating error or warning for program that is displayed to users as a popup box.

The last method, is <mark style="background-color:rgba(0, 0, 0, 0);color:#bb1212" class="has-inline-color">document.write()</mark>, that simply write to the document body wiping everything out except the output.

Advertisements

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Exit mobile version