JavaScript explained – a deep dive into the Web’s core language
JavaScript is the heart of modern websites - it makes pages respond, animate and communicate with the user in real time. In this article you will learn its definition, uses, advantages and practical code examples with explanations. You'll learn why JavaScript is a language that every web developer should know - no matter what your level is. The perfect start for beginners!

- 1. What is Javascript?
- 2. What is the history of Javascript?
- 3. What is the Javascript language used for?
- 3.1. Website interactivity
- 3.2. Manipulation of page content and structure (DOM)
- 3.3. Communication with the server (asynchronous)
- 3.4. Creating SPA (Single Page Application) applications
- 3.5. Form validation
- 3.6. Animations and visual effects
- 3.7. Working with APIs and integrations
- 3.8. Creating browser games
- 3.9. Building mobile and desktop applications
- 3.10. Server-side programming (Node.js)
- 4. What is the structure of JavaScript?
- 4.1. Variables – data storage
- 4.2. Data types – what information is made of
- 4.3. Operators – logic and actions
- 4.4. Conditional statements – decision making
- 4.5. Loops – repeating actions
- 4.6. Functions – code organization
- 4.7. Objects – representation of complex data
- 4.8. Arrays – storing multiple values
- 4.9. Eevents – user interaction
- 4.10. DOM – manipulating the page
- 4.11. JSON – data exchange
- 5. Javascript in practice – examples with explanation
- 5.1. Example 1: Displaying the welcome message
- 5.2. Example 2: Response to button click
- 5.3. Example 3: Dynamic change of page content
- 5.4. Example 4: Simple form validation
- 6. Advantages of JavaScript
- 6.1. Versatility
- 6.2. Integration with HTML and CSS
- 6.3. Huge community and support
- 6.4. Availability of libraries and frameworks
- 6.5. Support for all modern browsers
- 6.6. Low barrier to entry
- 6.7. Dynamic development
- 6.8. Versatility
- 6.9. Performance and instant interaction
- 6.10. Future prospects
- 7. Where can you write JavaScript code?
- 7.1. Inside the HTML document (in the <script> tag).
- 7.2. In the external .js file
- 7.3. In the developer console of the browser
- 7.4. In code editors (IDEs)
- 7.5. In online environments
- 8. Summary
- 9. FAQ – frequently asked questions about JavaScript
What is Javascript?
JavaScript is a dynamic, high-level programming language used primarily to create interactive elements of web pages. It allows responding to user actions, manipulating page content and communicating with the server without reloading the page. It runs directly in the browser and is one of the pillars of modern web development, along with HTML and CSS. It was created in 1995 by Brendan Eich at Netscape.
What is the history of Javascript?
JavaScript was born in 1995, when Brendan Eich – a programmer employed by Netscape Communications – was asked to create a scripting language to add interactivity to web pages. Interestingly, Eich created the first version of JavaScript in just 10 days. The language was originally called LiveScript, but for marketing reasons, Netscape decided to change the name to JavaScript to take advantage of the popularity of Java, which was gaining huge recognition at the time. Despite the similar name, JavaScript and Java are two completely different languages, with different syntax and usage.
Soon after its release, JavaScript was implemented in the Netscape Navigator browser, which began its rapid development. To ensure compatibility between different browsers, in 1997 the language was submitted to the ECMA (European Computer Manufacturers Association) organization for standardization, where the ECMAScript standard was created as a formal specification of JavaScript. Since then, the language has been regularly developed, with successive versions introducing new capabilities, improving performance and enhancing security.
Today, JavaScript is one of the pillars of website and web application development, used both on the client side (frontend) and server side (backend, such as using Node.js), and its history is an example of how a simple concept can turn into a global IT industry standard.
What is the Javascript language used for?
JavaScript is an extremely versatile language that is used in almost every layer of web application development. Its main task is to introduce interactivity into Web pages, but the scope of the language’s capabilities goes far beyond simple visual effects. Here are the most important areas where JavaScript is used:
1. Website interactivity
JavaScript enables you to respond to user actions, such as clicking buttons, moving the mouse, or entering text into forms. This makes websites more dynamic and engaging.
2. Manipulation of page content and structure (DOM)
JavaScript allows you to dynamically modify the structure of an HTML document (known as DOM – Document Object Model). For example, you can hide or show elements, change text, add new sections, or animate changes on the page.
3. Communication with the server (asynchronous)
Thanks to technologies such as AJAX, fetch() and libraries such as Axios, JavaScript can send and receive data from the server in the background – without the need to reload the entire page. This is a key element of modern web applications.
4. Creating SPA (Single Page Application) applications
JavaScript is the basis of single-page applications (SPA), which load once and then dynamically update content without reloading. Frameworks such as React, Vue, and Angular enable the creation of advanced user interfaces in this model.
5. Form validation
Before data is sent to the server, JavaScript can check that all required fields are filled in correctly. This saves the user time and reduces server load.
6. Animations and visual effects
JavaScript allows you to create smooth animations, transitions, sliders, drop-down menus, and interactive galleries. It can also be used in combination with CSS and libraries such as GSAP to create advanced effects.
7. Working with APIs and integrations
In today’s internet, many websites offer their data and functions through APIs. JavaScript allows you to connect to them, e.g., to retrieve data from weather services, maps, payment systems, or social media platforms.
8. Creating browser games
Thanks to engines such as Phaser or Three.js, it is possible to create 2D and 3D games that run in a browser and are fully based on JavaScript.
9. Building mobile and desktop applications
JavaScript, in combination with the right tools (e.g., React Native, Ionic, Electron), allows you to create mobile and desktop applications that run on multiple operating systems.
10. Server-side programming (Node.js)
JavaScript is not just frontend. With the Node.js environment, you can write backend code – i.e., server logic, database handling, user authorization, and many other functions.
What is the structure of JavaScript?
JavaScript is a language with a clear and flexible structure that allows you to build both simple scripts and complex applications. To understand how code is created in JavaScript, it is worth learning its basic elements – from variables, through functions, to objects and interactions with the browser. Below you will find an overview of the main components that form the “skeleton” of every program written in JavaScript.
1. Variables – data storage
Variables are used to store information. You can declare them in several ways:
let name = "Olga";
const age = 25;
let– used for variables whose value can change.
const– for constant values.
var– an older way, now less recommended.
2. Data types – what information is made of
JavaScript supports various data types:
- String (text) –
“Hello” - Number (numbers) –
10,3.14 - Boolean (logical) –
true,false - Array (arrays) –
[1, 2, 3] - Object (objects) –
{ key: “value” } - Null, Undefined – special types indicating no value
3. Operators – logic and actions
JavaScript offers mathematical operators (+, -, *, /), comparison operators (===, !=, <, >), and logical operators (&&, ||, !), which allow you to build conditions and dependencies.
4. Conditional statements – decision making
Conditional structures control the flow of a program:
if (age >= 18) {
console.log("Adult");
} else {
console.log("Underage");
}
5. Loops – repeating actions
Loops allow you to execute code repeatedly:
for (let i = 0; i < 5; i++) {
console.log(i);
}
6. Functions – code organization
Functions allow you to organize your code into logical blocks:
function welcome(name) {
console.log("Hi, " + name);
}
The modern syntax is the so-called arrow functions:
const total = (a, b) => a + b;
7. Objects – representation of complex data
Objects are data structures that contain properties and methods:
const person = {
name: "Kathirna",
age: 30,
introduce: function() {
console.log("Hello, ma name is " + this.name);
}
};
8. Arrays – storing multiple values
Arrays allow you to store sets of data:
let fruits = ["apple", "banana", "pear"];
console.log(fruits[0]); // apple
9. Eevents – user interaction
JavaScript responds to user actions, such as clicks
document.getElementById("btn").addEventListener("click", function() {
alert("The button was clicked!");
});
10. DOM – manipulating the page
The DOM (Document Object Model) allows you to dynamically change the content of an HTML page:
document.getElementById("HEADING").innerText = "New text";
11. JSON – data exchange
JSON (JavaScript Object Notation) is a popular data format, ideal for communicating with APIs:
let data = {
name: "Tomas",
age: 33
};
let json = JSON.stringify(dane); // conversion to JSON format
Javascript in practice – examples with explanation
To better understand how JavaScript works, it’s helpful to see it in action. Below you will find some simple but practical examples that demonstrate the basic capabilities of the language. Each code snippet includes a thorough explanation, so even beginners will easily understand what is going on in it.
Example 1: Displaying the welcome message
alert("Welcome to the world of JavaScript!");
What does this code do?
The alert() function displays a dialog box (known as an alert) that contains the text passed in. This is one of the simplest ways to interactively convey information to the user.
Example 2: Response to button click
<button onclick="sayHello()">Click me</button>
<script>
function sayHello() {
alert("Hello!");
}
</script>
Here we have a simple HTML page with a button. The onclick attribute runs the sayHello() function when clicked. This function – as before – displays a message using alert(). It’s a simple way to respond to user actions
Example 3: Dynamic change of page content
<p id="demo">Click the button to change this text.</p>
<button onclick="changeText()">Change the text</button>
<script>
function changeText() {
document.getElementById("demo").innerHTML = "Text was changed!";
}
</script>
This code demonstrates how JavaScript can affect HTML content. The getElementById() function searches for an element with a demo ID , and the innerHTML property allows you to change its content. The result? When the button is clicked, the text is updated – without reloading the page.
Example 4: Simple form validation
<form onsubmit="return validateForm()">
<input type="text" id="name" placeholder="Type name">
<input type="submit" value="Send">
</form>
<script>
function validateForm() {
let name = document.getElementById("name").value;
if (name === "") {
alert("The name cannot be empty!");
return false;
}
return true;
}
</script>
Here we check whether the user has entered a name before the form is submitted. If the field is empty, the validateForm() function stops the submission(return false) and informs the user of the error. This is called client-side validation – fast and convenient.
Advantages of JavaScript
JavaScript is one of the most widely used programming languages in the world, and for good reason. Its power lies in its versatility, ease of learning, and huge community support and toolset. Here are the most important advantages of JavaScript that make it the number one choice for many developers, both beginners and professionals:
1. Versatility
JavaScript works on both the client side (frontend) and the server side (backend – thanks to Node.js). This allows you to create complete applications in a single language, which simplifies the learning and development process.
2. Integration with HTML and CSS
JavaScript works perfectly with HTML and CSS, together forming the three technologies necessary for building modern websites. It allows you to dynamically change the style, content, and structure of a document in real time.
3. Huge community and support
JavaScript has one of the largest programming communities in the world. This makes it easy to find solutions to problems, tutorials, documentation, and ready-made libraries. Platforms such as Stack Overflow, GitHub, and MDN Web Docs are full of examples and tips.
4. Availability of libraries and frameworks
The JavaScript ecosystem is extremely rich. Frameworks such as React, Angular, Vue, and tools such as jQuery, Lodash, and Moment.js allow you to significantly speed up project development by eliminating the need to “reinvent the wheel.”
5. Support for all modern browsers
JavaScript is natively supported by every modern web browser – no additional software or installation is required. This makes it available to every Internet user right out of the box.
6. Low barrier to entry
The JavaScript syntax is relatively simple, and the first interactive effects can be achieved very quickly. This makes it an ideal language for beginners – you can quickly see the results of your work in the browser.
7. Dynamic development
JavaScript is constantly evolving. New versions of ECMAScript introduce more and more useful features (e.g., async/await, classes, destructuring), allowing you to write more modern, readable, and efficient code.
8. Versatility
In addition to typical websites, JavaScript can be used to create:
- mobile applications (React Native, Ionic),
- desktop applications (Electron),
- games (Phaser, Three.js),
- backend services (Node.js),
- automation (e.g., using Puppeteer).
9. Performance and instant interaction
JavaScript runs locally in the user’s browser, so some operations (e.g., form validation, animations) are instantaneous and do not require communication with the server.
10. Future prospects
JavaScript is an established technology in the industry that continues to grow and evolve. Knowledge of this language opens the door to many career paths – from frontend developer to fullstack developer to mobile app developer or even IoT developer.
Where can you write JavaScript code?
One of the reasons JavaScript is so popular is the ease of getting started – you don’t need a complex environment or special tools to start writing and testing your code. All you need is a browser and a basic text editor. Here are the most common places where you can create and run JavaScript scripts:
1. Inside the HTML document (in the <script> tag).
The easiest way to start your JavaScript adventure is to embed the code directly into the HTML file. This can be done in the <head> section or just before the end of <body>. Example:
<!DOCTYPE html>
<html>
<head>
<title>Example JS</title>
</head>
<body>
<h1>Welcome!</h1>
<script>
console.log("This is Javascript in HTML!");
</script>
</body>
</html>
2. In the external .js file
For larger projects, it is better to separate the JavaScript code from the HTML. You create a separate file, such as script.js, and then attach it to the HTML document:
<script src="script.js"></script>
This approach makes it easier to organize code, reuse functions and keep the project organized.
3. In the developer console of the browser
Every modern browser (Chrome, Firefox, Edge, Safari) has built-in developer tools (called DevTools), which include a JavaScript console. You can write and test code “live” in it, without having to save files. To open the console:
Chrome: F12 or Ctrl+Shift+I, tab “Console”
Firefox: F12 lub Ctrl+Shift+K
Safari: Cmd+Option+C
4. In code editors (IDEs)
For more advanced work, it is worth using editors that offer syntax hints, code coloring, automatic formatting, and integration with other tools.
Popular JavaScript editors include:
WebStorm – a paid IDE from JetBrains, offering advanced features for working with JavaScript and frameworks
Visual Studio Code – the most popular choice among developers, free and feature-rich
Sublime Text – lightweight and fast, with a large number of plugins
Atom – an editor from GitHub, flexible and open
5. In online environments
There are many platforms that allow you to write and test JavaScript without installing anything, e.g.: https://codepen.io/ or https://playcode.io/.
Summary
JavaScript is a versatile programming language that plays a key role in creating interactive and dynamic websites. Created in 1995 by Brendan Eich, initially as a simple script for form validation, it has evolved into a powerful tool used on both the client and server sides. Thanks to its flexibility and rich ecosystem of libraries and frameworks such as React, Angular, and Vue.js, JavaScript enables the creation of advanced web, mobile, and desktop applications. Its popularity also stems from its ease of learning and ability to integrate with other web technologies, making it an indispensable part of modern programming.
FAQ – frequently asked questions about JavaScript
1. Are JavaScript and Java the same thing?
No. Despite their similar names, JavaScript and Java are two completely different programming languages. Java is a statically typed language used in server, mobile, and desktop applications, among others. JavaScript is a dynamic scripting language used mainly in the creation of interactive websites and web applications. The name “JavaScript” was merely a marketing ploy.
2. Do I need to know JavaScript to create websites?
If you want to create modern, dynamic websites – yes. HTML and CSS allow you to create the structure and appearance of a website, but only JavaScript allows you to add interactivity, animation, respond to user actions, and communicate with the server. Knowledge of JavaScript is an absolute must for frontend developers.
3. Does JavaScript work on phones and tablets?
Yes. JavaScript works in mobile browsers exactly the same as it does on computers. What’s more, with frameworks such as React Native or Ionic, you can create native mobile apps for Android and iOS using JavaScript.
4. Where should I start learning JavaScript as a beginner?
It’s best to start with the basic syntax: variables, functions, loops, and events. You can use editors such as Visual Studio Code or test your code directly in your browser console. Recommended learning platforms include freeCodeCamp, Codecademy, JavaScript.info, and MDN Web Docs. Start with simple projects such as a calculator or a quiz.
5. Is JavaScript only suitable for websites?
No! Although JavaScript originated in browsers, its applications are much broader today. You can use it to create mobile apps (React Native), desktop apps (Electron), backends (Node.js), and even 2D and 3D games (Phaser, Three.js). It’s a truly versatile programming language.


