If HTML is a website's skeleton and CSS is its clothing, then JavaScript (JS) is its muscles and nervous system. Every action on a page, every animation, every piece of data loaded without a page refresh (AJAX) is done by JavaScript.
Today JS runs not only in the browser but also on the server (Node.js), in mobile apps (React Native) and even in games.
1. Modern JavaScript (ES6+) basics
Variables: let and const
The old var keyword has been left behind. Use const when a variable's value never changes and let when it can:
const platforma = "ALGOR.UZ";
let foydalanuvchilarSoni = 1500;
foydalanuvchilarSoni += 1; // Allowed
Arrow functions
A short, readable way to write code:
// A short function
const kvadrat = (x) => x * x;
console.log(kvadrat(5)); // 25
2. Working with arrays like a pro
In programming problems and in real projects alike, working with lists of data is the most common task. The most important JS methods:
const sonlar = [1, 2, 3, 4, 5, 6];
// 1. filter — keep only the even numbers
const juftSonlar = sonlar.filter(n => n % 2 === 0); // [2, 4, 6]
// 2. map — multiply every element by 2
const kopaytma = sonlar.map(n => n * 2); // [2, 4, 6, 8, 10, 12]
// 3. reduce — compute the sum
const jami = sonlar.reduce((sum, n) => sum + n, 0); // 21
3. Working with the DOM (Document Object Model)
JavaScript makes it very easy to change HTML elements dynamically:
// Find the button and attach a click handler to it
const tugma = document.querySelector("#yuborish-tugmasi");
tugma.addEventListener("click", () => {
alert("Solution accepted!");
});
4. Solving algorithmic problems in JavaScript
Many people think of JavaScript as just a "language for decorating websites". But a modern developer must be able to solve algorithms in any language, JavaScript included.
On the ALGOR platform you can solve any problem in JavaScript (Node.js). Your code goes through the same impartial judging on the server as C++ or Python.
Don't put learning off — try your first JS code right now in the ALGOR Compiler!