Starting with a question, what is JavaScript? We know JavaScript is a scripting language, and it is needed in web development. But many of us don’t know how it actually works or what is the role of JavaScript on the website? Let’s first take a look at what Wikipedia is saying.
The most common use of JavaScript is to add client-side behavior to HTML pages, also known as Dynamic HTML (DHTML). Scripts are embedded in or included from HTML pages and interact with the Document Object Model (DOM) of the page.
It is a technical definition. If we want to understand what JavaScript is, we have to go to its environment, i.e., the browser.
website-layers
Table of Contents
A modern website with content, beautiful design, interactive elements, etc. is created through three code layers. Which are,
- HTML Document
- CSS Rules
- JavaScript
HTML Document
The first layer is the HTML Document; In this layer, the website’s content is arranged in markup language so that the web browser can process it very easily. When you visit a website, you are actually accessing this document. The website does not exist without HTML Document.
CSS Rules
The second layer is the Collection of CSS Rules; This layer contains instructions for the browser through the CSS code on how to display HTML markup. The website presentation is a combination of HTML and CSS.
JavaScript
The third layer is JavaScript, which is our main topic. This is called the interactive layer of the website. JavaScript is the scripting language of the website that runs in the browser and interacts with HTML markup and CSS rules. JavaScript can modify and enhance HTML.
When you enter the address of a website in a web browser, the browser downloads, and indexes the website’s HTML document. Downloads the CSS and JavaScript file references in his HTML document. After downloading, first, run the JavaScript files. Running JavaScript files changes the HTML document a lot. Then the browser applies CSS rules to make the HTML document look beautiful.
JavaScript is still running in the background after this process is over. Because JavaScript has to be present in different actions of the visitor. For example, if you click on a button on a website, the browser will show you an alert message. This alert message was created with JavaScript. If JavaScript were not running in the background, this click-action would not show the alert message. This is why JavaScript is called the interactive layer.
So, in simple words, JavaScript is a scripting language with which you can write small programs and run them in the browser and convert them into HTML and CSS documents.