What are JavaScripts? Basic functions of JavaScript. What is Javascript? What kind of javascript program

The JavaScript programming language is an object-oriented scripting language originally developed by Netscape Communications under the name LiveScript, but later renamed "JavaScript" and with a syntax closer to Sun Microsystems' Java. JavaScript was later standardized by ECMA under the name ECMAScript. Microsoft calls its versions JScript.

The name change from LiveScript to JavaScript occurred around the same time that Netscape introduced support for Java technology in the browser. Netscape Navigator. This change has created a lot of confusion in the minds of those learning to program for beginners. There is no real connection between Java and JavaScript; their similarities begin and end with similar syntax and the fact that both languages ​​are widely used on the Internet.

JavaScript is an object-oriented scripting language that interacts through an interface called the Document Object Model (DOM) with content that can be executed on the server side (web servers) and on the client side in the user's web browser when viewing web pages. Many websites use client-side JavaScript technologies to create powerful dynamic web applications in programming for dummies. It can use Unicode and can use the power and strength of regular expressions (this was introduced in version 1.2 of Netscape Navigator 4 and Internet Explorer 4). JavaScript expressions contained as a string can be executed using the EVAL function.

One of the main challenges for JavaScript is small functions embedded in HTML pages and allow you to interact with the DOM from the browser to perform certain tasks that are not possible in static HTML: such as opening a new window, validating values ​​entered into a form, changing the image on hover, etc. Unfortunately, writing such functions is quite tedious because browsers are not standardized, different browsers may create different objects or scripting methods, and therefore you often have to write different versions JavaScript functions for various browsers, but this is not very convenient when learning the basics of programming.

JavaScript / ECMAScript is supported by such engines as:

  • Rhino
  • SpiderMonkey

Environment

The markup comment is required to ensure that the code does not display as text in browsers that do not recognize the . tags in XHTM/XML documents, however, will not work if commented out. Modern browsers, which support XHTML and XML are well designed enough to recognize , so in these documents the code remains uncommented.

An HTML element can generate internal events to which a script handler can be connected. To create the right HTML document 4.01, you need to insert an appropriate default script link statement in the document header section.

Elements of language

Variables

Variables are usually dynamically typed. Variables are defined either by simply assigning a value to them or by using the "var" operator. Variables declared outside a function are in "global" scope, visible throughout the web page; variables declared inside a function are local to that function. To pass variables from one page to another, the developer can set a "cookie" or use a hidden frame or window in background for their storage.

Data structures

The main type is an associative array data structure similar to hashes in the Perl programming language or Python, Postscript and Smalltalk dictionaries.

Elements can be accessed by numbers or associated names (if these have been defined). Thus, the following expressions may all be equivalent:

MyArray,
myArray.north,
myArray["north"].

Declaring Arrays

MyArray = new Array(365);

Arrays are implemented so that only certain (non-empty) elements will use memory, they "discharge the arrays". If we set the set myArray = "something there" and myArray = "something else there", then we have used space only for these two elements.

Objects

JavaScript has several kinds of built-in objects, namely Object, Array, String, Number, Boolean, Function, Date and Math. Other objects belong to DOM objects (windows, forms, links, etc.).

By defining constructor functions, you can define objects. JavaScript is a prototype-based object-oriented language. You can add additional properties and methods to individual objects after they have been created. To do this, you can use a prototype statement for all instances of a particular type of object.

Example: Creating an Object
// Constructor function

Function MyObject(attributeA, attributeB) ( this.attributeA = attributeA this.attributeB = attributeB )
// Create an object
obj = new MyObject("red", 1000)

// Access an object attribute
alert(obj.attributeA)

// Access attribute with associative array designation
alert(obj["attributeA"])

The hierarchy of objects can be reproduced in JavaScript. For example:

Function Base() ( this.Override = _Override; this.BaseFunction = _BaseFunction; function _Override() ( alert("Base::Override()"); ) function _BaseFunction() ( alert("Base::BaseFunction()" ); ) ) function Derive() ( this.Override = _Override; function _Override() ( alert("Derive::Override()"); ) ) Derive.prototype = new Base(); d = new Derive(); d.Override(); d.BaseFunction();

As a result, we get on the screen: Derive::Override() Base::BaseFunction()

Control instructions
If ... else if (condition) ( statements )
Cycles
while (condition) ( statements ) Do ... while do ( statements ) while (condition); For loop for (; ; ) ( statements ) For loop ... in
This loop goes through all the properties of an object (or element in an array)
for (variable in object) ( statement )

Selection operator
switch (expression) ( case label1: statements; break; case label2: statements; break; default: statements; )

Functions
The body of the function is contained in (the body can be empty), and the list of arguments is indicated inside () following the function name. Functions can return a value after execution.

Function(arg1, arg2, arg3) ( statements; return expression; )

As an example, let's look at a function based on the Euclidean greatest common divisor algorithm:

Function gcd(a, b) ( while (a != b) ( if (a > b) ( a = a - b; ) else ( b = b - a; ) ) return a; )

The number of arguments when calling a given function does not necessarily have to provide as many arguments as were specified when the function was declared. In a function, arguments can also be accessed through an argument array.

Each function is an instance of a function, a base type of object. Functions can be created and assigned like any other objects:

Var myFunc1 = new Function("alert("Hello")"); var myFunc2 = myFunc1; myFunc2();

Result on screen:

User interaction

Most user interaction is done using HTML forms, which can be accessed through the HTML DOM. However, there are also some very simple remedies communication with the user:

Alert dialog box
Confirm dialog box
Dialog lines
Status bar
Consoles

Text elements can be the source of various events, which can trigger actions if an EMCAScript event handler is registered. In HTML, these event handler functions are often defined as anonymous functions directly in the HTML tags.

JavaScript was created by programmer Brendan Eich of Netscape and introduced in December 1995 under the name LiveScript. Quite quickly it was renamed JavaScript, although the official name for JavaScript is ECMAScript. ECMAScript is developed and maintained by the international organization ECMA (European Computer Manufacturers Association).

What is JavaScript?
1) JavaScript is a scripting or scripting language. A script is a program code - a set of instructions that does not require pre-processing (for example, compilation) before running. The JavaScript code is interpreted by the browser engine while the web page is loading. The browser interpreter performs line-by-line analysis, processing, and execution of the original program or request.

2) JavaScript is an object-oriented language with prototypical inheritance. It supports several built-in objects and also allows you to create or delete your own (custom) objects. Objects can inherit properties directly from each other, forming an object-prototype chain.

JavaScript on web pages 1. Connecting scripts to an HTML document

JavaScript scripts can be inline, i.e. their contents are part of the document, and external ones are stored in a separate file with the .js extension. Scripts can be embedded in an HTML document in the following ways:

or the body of the page.

This method is typically used for large scripts or scripts that are used multiple times across different web pages.

As an event handler.
Each html element has JavaScript events that fire at a certain moment. You need to add the required event to the html element as an attribute, and specify the required function as the value of this attribute. A function called in response to an event firing is an event handler. When an event is triggered, the code associated with it will be executed. This method is used mainly for short scripts, for example, you can set the background color to change when you click on a button:

var colorArray = ["#5A9C6E", "#A8BF5A", "#FAC46E", "#FAD5BB", "#F2FEFF"]; // create an array with background colors var i = 0; function changeColor())( document.body.style.background = colorArray[i]; i++; if(i > colorArray.length - 1)( i = 0; ) ) Change background

Inside the element.
The element can be inserted anywhere in the document. Inside the tag is code that is executed immediately after being read by the browser, or contains a description of the function that is executed at the time it is called. The function description can be placed anywhere, the main thing is that by the time it is called, the function code has already been loaded.

Typically, JavaScript code is placed in the head of the document (the element) or after the opening tag. If the script is used after the page has loaded, for example, the counter code, then it is better to place it at the end of the document:

document.write("Enter your name");

2. Data types and variables in JavaScript

Computers process information—data. Data can be presented in various forms or types. Most of JavaScript's functionality is implemented through a simple set of objects and data types. String, number, and logic functionality is based on string, numeric, and Boolean data types. Other functionality, including regular expressions, dates, and math operations, is done using the RegExp, Date, and Math objects.

Literals in JavaScript are a special class of data type, fixed values ​​of one of three data types - string, numeric, or boolean:

"this is a string" 3.14 true alert("Hello"); // "Hello" is a literal var myVariable = 15; // 15 is a literal

A primitive data type is an instance certain type data such as string, numeric, boolean, null and undefined.

2.1. Variables in JavaScript

The data processed by the JavaScript script is variables. Variables are named containers that store data (values) in computer memory that can change during program execution. Variables have a name, a type, and a value.

The variable name, or identifier, can only include letters a-z, A-Z, numbers 0-9 (the number cannot be the first character in a variable name), the $ symbol (can only be the first character in a variable or function name) and the underscore character _, spaces are not allowed. The length of the variable name is not limited. It is possible, but not recommended, to write variable names in letters of the Russian alphabet; for this they must be written in Unicode.

Keywords cannot be used as variable names JavaScript words. Variable names in JavaScript are case sensitive, which means that the variable var message; and var Message; - different variables.

The variable is created (declared) using keyword var followed by the variable name, for example var message; . You must declare a variable before using it.

A variable is initialized with a value using the assignment operator = , for example, var message="Hellow"; , i.e. a message variable is created and its initial value "Hello" is stored in it. A variable can be declared without a value, in which case it is assigned the default value of undefined . The value of a variable can change during script execution. Different variables can be declared on the same line, separated by a comma:

Var message="Hello", number_msg = 6, time_msg = 50;

2.2. Variable Data Types

JavaScript is an untyped language; the data type for a specific variable does not need to be specified when declaring it. The data type of a variable depends on the values ​​it accepts. The type of a variable can change during data operations (dynamic type casting). Type conversions are performed automatically depending on the context in which they are used. For example, in expressions involving numeric and string values ​​with the + operator, JavaScript converts the numeric values ​​to string values:

Var message = 10 + "days before vacation"; // will return "10 days until vacation"

You can get the data type of a variable using the typeof operator. This operator returns a string that identifies the corresponding type.

Typeof 35; // return "number" typeof "text"; // return "string" typeof true; // return "boolean" typeof ; // return "object" typeof undefined; // will return "undefined" typeof null; // return "object"

All data types in JavaScript are divided into two groups - simple data types (primitive data types) and composite data types (composite data types).

Simple data types include string, numeric, boolean, null, and underfined.

2.2.1. String type

Used to store a string of characters enclosed in double or single quotes. An empty set of characters enclosed in single or double quotes is the empty string. A number enclosed in quotes is also a string.

Var money = ""; // empty string, zero characters var work = "test"; var day = "Sunday"; var x = "150";

You can include a single quote within a double-quoted string, and vice versa. A quotation mark of the same type is escaped using the backslash character \ (called an escape sequence):

Document.writeln("\"Good morning, Ivan Ivanovich!\"\n"); // will display "Good morning, Ivan Ivanovich!"

Strings can be compared and also combined using the concatenation operator + . Thanks to automatic type casting, you can combine numbers and strings. Strings are permanent, once a string is created it cannot be modified, but a new string can be created by concatenating other strings.

2.2.2. Numeric type (number)

Used for numeric values. Numbers in Java language Script come in two types: integers (integer) and floating point numbers (floating-point number). Integer values ​​can be positive, such as 1, 2, negative, such as –1, –2, or zero. 1 and 1.0 are the same value. Most numbers in JavaScript are written in decimal system number systems, octal and hexadecimal systems can also be used.

In the decimal system, the values ​​of numeric variables are specified using Arabic numerals 1, 2, 3, 4, 5, 6, 7, 8, 9, 0.

In octal format, a number is a sequence containing the digits 0 through 7, starting with the prefix 0.

For hexadecimal format, the prefix 0x (0X) is added, followed by a sequence of numbers from 0 to 9 or letters from a (A) to f (F), corresponding to values ​​from 10 to 15.

Var a = 120; // integer decimal numeric value var b = 012; // octal format var c = 0xfff; // hexadecimal format var d = 0xACFE12; // hexadecimal format

Floating point numbers are numbers with a fractional decimal part, or they are numbers expressed in scientific notation. Scientific notation of numbers assumes the following form: a number with a fractional decimal part, followed by the letter e, which can be indicated in both upper and lower case, then an optional + or - sign and an integer exponent.

Var a = 6.24; // real number var b = 1.234E+2; // real number, equivalent to 1.234 X 10² var c = 6.1e-2; // real number, equivalent to 6.1 X 10‾²

2.2.3. Boolean type(boolean)

This type has two values, true, false. Used to compare and test conditions.

Var answer = confirm("Did you like this article?\n Click OK. If not, click Cancel."); if (answer == true) ( ​​alert("Thank you!"); )

There are also special types of simple values:
null type - this type has a single null value, which is used to represent non-existent objects.

undefined type - the variable type underfined means the absence of the initial value of the variable, as well as a non-existent property of the object.

Composite data types consist of more than one value. These include objects and special types of objects—arrays and functions. Objects contain properties and methods, arrays are an indexed collection of elements, and functions consist of a collection of statements.

2.3. Global and local variables

Variables by scope are divided into global and local. A scope is the part of a script within which a variable name is associated with that variable and returns its value. Variables declared inside the body of a function are called local variables and can only be used within that function. Local variables are created and destroyed along with the corresponding function.

Variables declared inside an element, or inside a function, but without using the var keyword, are called global. They can be accessed as long as the page is loaded in the browser. Such variables can be used by all functions, allowing them to exchange data.

Global variables end up in the global namespace, which is where individual program components interact. It is not recommended to declare variables in this way because similar variable names may already be used by other code, causing the script to crash.

Global space in JavaScript is represented by the global window object. Adding or changing global variables automatically updates the global object. In turn, updating the global object automatically updates the global namespace.

If a global and a local variable have the same name, then the local variable will take precedence over the global one.

Local variables declared within a function in different code blocks have the same scope. However, it is recommended to place all variable declarations at the beginning of the function.

Previously, I did not think that the Internet could provide such extensive opportunities for developing my business, but time passed and I finally discovered this world full of opportunities. The Internet provides an opportunity to sell your products, a wide variety of them. Every day the number of users world wide web is growing, and at the same time our capabilities are growing.

Once upon a time I did not understand many of the earning schemes, but today I can say with complete confidence that the basis of any business on the global network is a website. Moreover, not just a site, but the right site. Moreover, many factors influence whether the site will be profitable. The first thing a visitor to any website encounters is the interface.

Believe me, how attractive the site is will determine whether a casual user will stay on it or not. Of course, if a person has been reading your site for a long time, then he will forgive you for various mistakes that you may make in the functionality of the site. But for the first time, the interface will play a key role in making the client like your website. As they say, “they are greeted by their clothes, they are seen off by their minds.”

But in order to make original and memorable clothes for your site, you will need to know what javascript is for. In fact, without JavaScript it is impossible to create a beautiful, functional website. Moreover, there will be no need to clutter the site with tons of code. It will be enough to add just a couple of lines, and various buttons and menu items will “come to life” and become more attractive. By the way, a JavaScript script will allow you to scroll through pictures in your portfolio. In addition, you can further increase the functionality of the page when displaying data. JavaScript is also needed here

Perhaps many may think that, for example, it works on a good CMS, and to manage such a blog you do not need JavaScript knowledge at all. On the Internet you can find many different modules and plugins with which you can significantly improve functionality, add cool effects, etc. However, we should not forget that web technologies do not stand still, everything is constantly changing. Therefore, it is worth constantly monitoring the emergence of new JavaScript libraries, because it is possible that today's packages will make it possible to realize what only yesterday seemed just a dream. That’s why when they talk about updating a site, they also mean the use of JavaScript.

Now for learning JavaScript. For some reason, many people believe that learning this programming language is only available to a select few. But actually it is not. Web programmers are constantly working on creating new JavaScript elements, which greatly simplify its syntax and use. In addition, you can use JavaScript code on the pages of your site if you know how to use the appropriate manuals. Wonderful video courses will come to the rescue with this, with the help of which even a complete layman can master JavaScript in a short time.

I would like to express my gratitude to Evgeniy Popov, the author of a number of video courses on website building, for information support. Including the video course “Javascript + jQuery for beginners in video format”

JavaScript® (often shortened to JS) is an interpreted programming language designed for interacting with web pages. JavaScript runs on the client side of the Internet and is used to program how web pages will behave when certain events occur.

What is JavaScript?

JavaScript is a cross-platform, object-oriented scripting language that adds interactivity and responsiveness to your web pages.

JavaScript allows the website developer to control how the web page behaves. This makes JavaScript fundamentally different from HTML, the language that is responsible for the structure of a web document, and CSS, the language that forms appearance web pages.

Programs written in JavaScript are called scripts. In the browser, they are connected directly to the HTML document and, as soon as the page loads, they are immediately executed. The process of executing a script is called "interpretation".

If PHP script processed on the server side with using PHP interpreter, then JavaScript is executed in the user's browser by the JavaScript interpreter.

Today, every browser supports JavaScript, making it the language of the web.

IN JavaScript browser can do everything related to manipulating the HTML document, interacting with the visitor and, with some limitations, with the server:

  • Check that custom HTML forms are filled out correctly.
  • Interact with your webcam, microphone and other devices.
  • Change the styles of HTML elements, hide, show elements, etc.
  • Display pop-ups and dialog boxes.
  • React to visitor actions, process mouse clicks, cursor movements, etc.
  • Send requests to the server and load data without reloading the page.

JavaScipt is an incredibly powerful and efficient language that you should definitely try!

JavaScript vs ECMAScript

This tutorial is written about a language that is known as JavaScript. However, the official standard that defines the specifications that describe the language calls it ECMAScript.

Netscape submitted the JavaScript language to the Ecma International organization, whose activities are dedicated to the standardization of information and communication systems(ECMA was originally an acronym for the European Computer Manufacturers Association), where it was adopted as the ECMAScript standard in 1997.

This standardized version of JavaScript, called ECMAScript, works the same in all applications that support the standard. Developers can use the open language standard to develop their own implementation of JavaScript.

Formally, when developers refer to ECMAScript, they are usually referring to the "ideal" language defined by the Ecma standard. Most often, these two concepts are interchangeable. Therefore, when referring to the official standard in this tutorial, the name ECMAScript will be used, and in other cases when referring to the language, JavaScript will be used. The textbook will also use the common abbreviation ES5 when referring to the fifth release of the ECMAScript standard.

JavaScript is not Java

Before you start learning JavaScript, you should understand that JavaScript is not Java. These two are perfect different languages programming. JavaScript has nothing in common with the Java language other than its similar syntax.

Java is an object-oriented programming language developed by Sun Microsystems since 1991 and officially released on May 23, 1995. Java is a powerful and much more complex programming language, you can write the most different programs. There is a special opportunity for Internet pages - writing applets.

An applet is a Java program that can be connected to HTML using the . Java applets are run using a compiler. Java applets are embedded in a web page but stored on disk as separate files. These are binary files and if you open them you won't see them source applet.

JavaScript scripts reside within a web page and cannot exist separately from it. JS scripts do not require a compiler to execute; they are executed by the browser on the user's side. JS script is plain text, and you can view the code with your naked eye - without any special software.

Java is a class-based language that is fast, high level protection and reliability. Java's class-oriented model means that programs consist solely of classes and their methods. Class inheritance and strong typing in the Java language typically require tightly coupled object hierarchies. These requirements make Java programming more complex than JavaScript programming.

JavaScript is a lightweight programming language that has a simple syntax, specialized built-in functionality, and minimum requirements to create objects. You don't need to declare variables, classes and methods. You don't have to worry about whether methods are public, private, or protected, and you don't have to implement interfaces. Variables, parameters, and function return types of JS scripts are not explicitly typed.

What do you need to learn JavaScript?

No prior knowledge of JavaScript is required, but since JavaScript resides within web pages and controls their dynamics, it is assumed that you are familiar with the basics of HTML, although it is possible that JavaScript will run in parallel.

Majority JavaScript scripts are designed to “revive” HTML, i.e. the purpose of creating a script is to demonstrate how the appearance of the page will change when changing the values ​​of the HTML tag parameters. Collected and properly formatted, these types of scenarios are an example of a developed web application.

Before we start writing our first JavaScript program, it is very important to make sure that we have all the necessary tools configured and in place.

When learning JavaScript, it's important to run the examples presented in each lesson, modify them, and run them again to see how well you understand the material you've learned. This requires a JavaScript interpreter. Luckily, as you already know, every web browser includes a JavaScript interpreter.

To write and execute JavaScript programs, it is enough to install any modern Internet browser (for example, Yandex, Internet Explorer, Mozilla Firefox or Google Chrome).

Later in this tutorial, you'll see that JavaScript code can be embedded directly in HTML files, in tags, and when the HTML file is loaded, the code will be executed by the browser. It's worth noting that you don't need to do this every time you want to test a short snippet program code JavaScript.

The easiest way to experiment with JavaScript code is to use your browser's built-in Web Console tool.

Typically, the web console can be launched by pressing the F12 key or the hotkey combination – Ctrl + Shift + J. Typically, the panel or window of a typical “developer tool” opens as a separate panel at the top or bottom of the browser window, as shown in Fig. 1.

The panel includes many tabs that allow you to explore the structure of an HTML document, CSS styles etc. Among them is the JavaScript Console tab, where you can enter lines of JavaScript code and execute them.

For more detailed analysis we need program code text editor with additional functionality that simplifies writing and editing program code. As such, we will use the Notepad++ editor. If you are already using another editor and have managed to get used to it, then there is nothing stopping you from continuing to use it.

With most of the examples given in our tutorial, you can experiment directly on the site page using the built-in tool - the JS mini-editor.

In order to see the result of running the script in a new window, click on the icon, and if you want to change something in the code, click on the icon

This is a regular HTML document

We exit back to HTML

Please note: In simple JavaScript experiments like this, you can omit the , tags in the HTML file as well.

Learning JavaScript, like other programming languages, is not an easy task, but it is definitely worth the effort and time. Learning is effective when it is given not just like that, but with effort. You must make a conscious effort to learn new skills and abilities. Knowledge acquired without effort is like ripples on the water - very soon not a trace will remain of it.

From e-books to free online courses to challenge-based learning platforms, the options for quality knowledge sources are almost limitless today. But how to motivate yourself to self-study How to learn to study independently?

Try following a few simple but proven tips.

You need to study little by little, but regularly. Regularity is the key to success in learning. Plan your daily routine so that you can devote at least one hour every day to learning JavaScript. Don't try to learn everything at once in a short period of time. Breaking the self-education process into small study sessions creates a feeling of quick success and motivates you to return to learning the next day.

The worst time to study is when you feel tired. At such moments, the main thing is not to force yourself - you will not get the expected result. The human brain cannot learn something indefinitely - it needs to be given breaks. Practice according to the 25/5 principle. Try the practice of teaching for 25 minutes and resting for 5 minutes. Your brain will get used to such uniform loads and will work as productively as possible.

Use recollection practices - the basis of learning. The more often we recall information, the longer it will be stored in our memory.

An effective recall technique is delayed recall: on a card, on one side, write a question that relates to the material you studied, and on the other, the answer to it. Learn the contents of the card, and then, after a day, try to remember the answer. If you gave the correct answer, the card can be put aside for a week until the next repetition. If you make a mistake, you need to repeat the question the next day. The longer your chain of successful answers, the longer the interval should be before the next repetition.

In parallel with theoretical studies, constantly practice. To gain practical experience, you just need to write a lot and analyze examples of good code. When working through the examples, carefully go through all the lines of code - you must make sure that you understand how each line works. Don't be afraid to experiment. Learn to display some data in a browser window and analyze it. For example, what is displayed on the screen and after what, did you get what you wanted, and if not, then why.

Whatever learning method you choose, do not forget that it should be interesting for you and supported by practical exercises - examples are worth a thousand words. Examples are often easier to understand than a multi-page theory. So be bold! I hope that this tutorial will be a good help in your endeavors.

If you are not yet familiar with the concept of Javascript, then about this.

In this note I wanted to talk about why Javascript is needed and what you can do with it.

Like any programming language, the main task of Javascript is to create a sequence of actions that will lead to a specific result.

These can be “if-then” conditions, loops that create a certain sequence of actions, mathematical calculations, etc.

The most important thing is that all these operations can be performed on web pages, in a browser window. Moreover, javascript can work without an Internet connection.

So let's look at a number of examples that demonstrate the capabilities that can be achieved using Javascript. I have conditionally sorted them into several groups so that you have a certain understanding of what Javascript does and why it is needed.

1) Mathematical operations

On web pages, there is often a need to make certain calculations.

For example, there are two text fields and you need to display in the third text field the sum of two numbers that are entered in the first two.

Using Javascript, you can create a calculator and place it on a web page.

Here is an example of such a calculator:

Another situation, let’s take some text string on a web page, we need to increase its size by 1.5 times. This can also be done using mathematical calculations, by multiplying the current size by a factor of 1.5.

There are a lot of tasks that require calculations in practice. Javascript allows you to do all this.

2) Processing and validating data in HTML forms

Javascript allows you to check that all required fields are filled in and the data they contain matches the required format(for example, if numbers are required, then there should be only numbers and no letters).

Javascript does this without reloading the page and even without connecting to the Internet.

Before sending data to the server, it is pre-checked in Javascript. This reduces the load on the server.

3) User interactions and events

Various effects may appear on a web page depending on what actions the user performs.

Drop-down menu on the site when hovering the mouse cursor.

When you click on a button, hide or show some element on the page.

A pop-up window appears when the mouse cursor moves outside the browser window.

Blackout background and element fade-in effects are implemented in Javascript.

4) Interact with HTML elements on the page and manipulate their content and styles.

When a certain event occurs (for example, a mouse click or any other), you can change the appearance (CSS styles) of elements on the page.

This is all done programmatically.

You can also add some HTML tags or attributes to them, also when a certain event occurs.

5) Adding animation and various graphic effects to web pages.

Falling and moving objects. For example, snow on the site.

Smooth appearance and hiding of objects

Countdown timer

And other effects are implemented in Javascript

I have listed here just a small list of Javascript features. So that you can see everything clearly and with real examples, here is a list of sites where working examples in javascript are published:

The capabilities and scope of Javascript are actually very extensive. Everything will be limited only by your imagination and creativity.