Why on sites used javascript and what it is
- Mar 11
Many people who require the site have heard that when it is created, JavaScript is used, but what it is for what is needed is not particularly understood. We have already talked about HTML and CSS and figured out that these are special markup languages and styles, without which the site's fascos is impossible. JavaScript is the third component, which is usually also used, but it is not so mandatory. Without it, you can do, but it is still much better with him.
So, let's see what it is in general.
If HTML and CSS allow you to create a site markup and give it beauty, then JavaScript is a programming language. It refers to high-level languages, that is, a program, or a script, is written on it using a set of commands - operators similar to ordinary English words. And then the code handler, which is called the engine, translates them into a clear computer machine code.
JavaScript has a lot of tools and features. It can work with textual and numeric data, arrays, you can write your functions in it or use ready-made. In general, it allows you to write programs of any complexity.
But what are the sites here? The fact is that JavaScript is embedded in almost all browsers, and they can perform programs written in this language. Therefore, they can be implemented directly to the site page and receive different interesting things.
On any open site page, different events may occur that the browser tracks. For example, this is a scrolling of the page up or down, hovering the cursor to the block, a picture, link, click on the link or other object. There are many such events, but the browser does not respond to them.
How to make that during these events on the page something happened? Something can be done using CSS. For example, implement some effect when you hover the cursor or when clicking on the object. They brought the cursor on the button - she changed the color or size, brought to the picture - she leaned or became round ... or you can make a simple parallax effect if you fix the background picture. These are actions that decorate the design, make it alive and original, but no practical benefit is given to the visitor.
Applying a programming language, such as JavaScript, allows you to set logic events. The principle here is simple - a function is written for a specific event in which the necessary actions are programmed. They can be both simple and complex.
By pressing the button or icon, you can shift some elements aside and on their place to show others - the sliders that you have seen on many sites are created. Or for some formula, the result is calculated from the data entered in the field - calculators are so implemented.
JavaScript is also used to validate forms - data check before shipping. This form will not send a message to the server if the field with the phone number or another is filled incorrectly.
JavaScript creates beautiful animations and effects. It is possible to even connect special libraries and add 3D graphics to the site.
There are different ways to connect JavaScript to the site. If you need one or more small scripts on the page, you can insert them directly into its HTML markup. This is done with the help of special tags that are placed in the football site. So, for example, statistical scripts are usually added - Yandex.Metrica, Google Analytics and others.
If a lot of scripts are used on the site, and they are large, then they are placed in a separate file, which has an extension JS. It also connects in a foothold with a link to it.
The second way is used more often, as it allows you to divide different parts of the site. It is so convenient - first the markup of the HTML page is written, the CSS style file is connected to it and then the file with JavaScript scripts in which the functionality is separately written.
When all these files are loaded with a browser, it starts tracking what is happening on the event page and if certain functions are prescribed for them, then performs them.
It should be understood that the script written in JavaScript and connected to the site is performed only in the browser when the page is loaded and displayed on the screen. At the same time, access to the computer file system is prohibited - this is done for security purposes. That is, the script from the site can not, for example, find a folder with photos on your computer and send them to someone. Or something to remove from the disk. The browser tab where it is performed is isolated even from other tabs.
However, JavaScript can still go beyond the browser and send data, but only those that have been calculated or entered on the user page. And it can only pass them on the site server, from where the page was downloaded, and more nowhere. This restriction is also done with the purpose of security.
But on the most uploaded page, the script can do anything - everything is limited only by the capabilities of the JavaScript language and the fantasy of the programmer. Now you can meet many sites on which creative ideas are implemented - dynamic backgrounds, 3D graphics, beautiful transitions between pages, sliders of different types, and much more. The most unusual sites even look like mini-games.
All this is possible due to the huge number of ready-made libraries. They contain many professionally written features that can be connected to their site and immediately use. It greatly simplifies and speeds up the development, makes it better, as the libraries have already been tested and optimized, and the developer does not need to write all these functions from scratch. For example, you can simply connect a library to the site with animations and get beautiful effects for any objects on the page.
The JavaScript language gives great opportunities and allows you to "revive" the site, give it any functionality, which is only required, and this is its main purpose.