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.

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

JavaScript inside HTML page

    document.write(“Hello world”);

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.

  • document.getElementById(“demo”).innerHTML = ‘hello”;
  • console.log(“Hello”);
  • alert(“hello”);
  • document.write(“Hello”);

The first method is using HTML DOM and selector API functions like getElementById, etc.

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 document.write(), that simply write to the document body wiping everything out except the output.

Please support us by disabling your adblocker or whitelist this site from your adblocker. Thanks!

turn of adblocker imag