An brief introduction to vanilla javascript

October 3, 2022

What is Javascript?

JavaScript is a cross-platform, object-oriented scripting language used to make webpages interactive (e.g., having complex animations, clickable buttons, popup menus, etc.). There are also more advanced server side versions of JavaScript such as Node.js, which allow you to add more functionality to a website than downloading files (such as realtime collaboration between multiple computers).

Where to write Javascript?

JavaScript can be added to your HTML file in two ways:

  • Internal JS: We can add JavaScript directly to our HTML file by writing the code inside the <script> tag. The <script> tag can either be placed inside the <head> or the <body> tag according to the requirement.
  • External JS: We can write JavaScript code in other file having an extension.js and then link this file inside the <head> tag of the HTML file in which we want to add this code.

Javascript Syntax

alert("This is alert!")

Example 

File 1: js-intro.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Javascript Intro</title>
</head>

<body>
    <script>
        alert("This is Javascript");
    </script>
</body>

</html>

<script> & </script> are opening and closing tags for writing javascript.

alert() is method that is used to display an alert box with a message and an OK button.

More javascript rules and techniques will be explained in upcoming chapters.

Comments ()