What you can’t do without JavaScript

Let’s look at what you can do in JS, what you can’t do in another language, and why it will be related to JS anyway.

As it happens, it is not enough to know only HTML and CSS to create a website – it will turn out static. Add PHP, and the pages become dynamic. But if you want interactivity, you’ll need JavaScript. Of course, you can use CSS to create animation, sometimes even a complex and beautiful, but this does not reach the stage of real interactivity, because CSS can change the look of the page, but it can not add new elements, respond to specific user actions, make the animation smoothly or at a certain interval.

And a lot of it comes down to adaptability: CSS forces you to write extra code for mobile devices, while JS always works the same unless the user has turned it off and unless it’s IE6.

Why JavaScript is needed

JavaScript is a scripting language. It can be used to track events and record reactions to them:

  • Hover the mouse over an item (event) – expand the list (response).
  • Clicked the button – display a message.
  • Changed value in the field – make calculations and print the result.
  • Clicked a button on the keyboard – shift focus to the field, so the user does not type into a blank space.
  • Triggered timer – change the background of the element.
  • This is just a small list of the possible events and reactions.

What languages are responsible for

JS allows a very wide range of possibilities, both in terms of the animation itself, and in terms of the events that can trigger a reaction.

You can create a slider in JS with just a couple lines of code.

Interactive Elements

Interactive elements are a specialty of JavaScript. The most common example is online calculators. You choose different parameters, and you immediately calculate the cost.

Pop-ups can be of three types:

  • modal;
  • A new window with a separate document;
  • popup.

Communication with the server

The language provides the ability to send a request to the server and get a response at any time. This technology is called AJAX, and it still has no direct analogues. To use AJAX, you need to connect the jQuery library.

Let’s say you are creating a weather center website. You need a user to be able to click on a number on the calendar and immediately get the forecast.

In JS you can also:

  • draw on canvas;
  • Create control panels for audio and video elements;
  • work with cookies;
  • search for information on a page;
  • scroll a document.

And that’s just part of the possibilities.