Scripts can be written inside the page code or connected to HTML as a separate file. For example, in the standard index.html markup, JS code is written inside the script tag placed in the body tag.
JS is a multi-paradigm language, as it supports different programming paradigms (styles):
- Object-oriented – represents the program as a system of relations between objects – sets of data and functions.
- Imperative – This style of programming uses instructions that are executed sequentially, and variables are used to access data, the value of which can be rewritten during the calculation.
- Functional – in it, the calculation is based on mathematical functions. Since functional programming does not rely on variables that can change value, the results of queries will always be the same.
The client part of web applications (frontend). This is the interface of the page, that is, everything that the user sees: content, buttons, feedback forms, menus. Using JS, the interface responds to user actions (mouse clicks, keystrokes), and the language is also responsible for storing data and autofilling forms.
What is JS for?
- HTML data processing. JS helps fill in the required fields in forms, validate literal and numeric values, and manage HTML elements on the page. For example, in the Tilda landing page builder, you can drag and drop blocks and change fonts, text colors, background colors, and other values on click.
- Mathematical calculations. With the help of JS scripts, calculators are implemented on websites, for example, calculating the amount of an order in an online store basket.
- The user performs an action – clicks on the “Register” button.
- The browser fixes the fulfillment of certain conditions – a mouse click in a specific area on the page. The onclick command is responsible for the reaction to the action, which launches the prescribed JS code.
- Then the JS code that is written for these conditions is launched – the animation of pressing the button and opening the registration form.
- The page is completely or partially updated – depending on the settings, the form can open in the same or in the next tab.