JavaScript is the programming language used to develop various types of applications which runs on the browser.

JavaScript is a simple and powerful language in the contemporary world.

Using JavaScript someone can develop Web, Mobile, Server-side applications.

Let us try to understand how we can get started with JavaScript. For executing the JavaScript, you don’t require any compiler it just run on the browser.

Getting start with JavaScript.

To start with JavaScript, we need a .html file and attach the JavaScript in the .html file. JavaScript is written in <script></script> tags.

Inline script


<!DOCTYPE HTML>
<html>

<body>

  <p>Before the script...</p>

  <script>
    alert('Hello, world!');
  </script>

  <p>...After the script. </p>

</body>

</html>

JavaScript executes from top to bottom approach like from line 1 to line “n”

External JavaScript File reference

Separating the JavaScript file in an external file. i.e separating the .html file and .js file. .html file contains the html content and .js file contains the JavaScript code.

From the above example JavaScript code will be move to a separate file sample.js and adding the file reference in the .html file.

<!DOCTYPE html>
<html>

<head>
    <title>
        External JavaScript
    </title>
    <script src="sample.js"></script>
</head>

<body>
    <h2>
        External JavaScript
    </h2>

    
</body>

</html>

Reference from other external sources

Reference of the .js file can also be added form the external sources. e.g. from the other hosted location.

<!DOCTYPE html>
<html>

<head>
    <title>
        External JavaScript
    </title>
    <script src="http://www.ktbrain.com/sample.js"></script>
</head>

<body>
    <h2>
        External JavaScript
    </h2>

    
</body>

</html>

JavaScript is uses.

  • Developing browser-based applications.
  • It runs and executes on the browser (Internet Explorer, Edge, Chrome, Safari, Firefox etc.)
  • HTML DOM modifications cab be done.
  • Interactive application development can be done.