What Is JavaScript and How Does It Work? Beginner Guide
JavaScript is the programming language that adds behavior to web pages and runs right in the browser. In this lesson you'll see what it's for, how the engine runs your code, and where to try your first line.

Contents
The short answer to the question of what JavaScript is: JavaScript (JS) is a programming language that adds behavior to web pages and can run both in the browser and on the server. HTML builds the skeleton of the page, CSS builds its appearance; JavaScript writes the interaction such as clicks, form validation, animation, and data updates. This lesson is part of the JavaScript: From Zero to Hired series and was prepared based on the ECMAScript 2026 standard (the version published in June 2026) and the current stable Chrome and Node.js Active LTS versions at the time of writing; you can verify the version numbers from the chrome://version screen and the nodejs.org/en/about/previous-releases page.
What you’ll learn in this lesson
- Explain what JavaScript is and what role it plays alongside HTML and CSS
- Describe at a high level how JavaScript code is executed by the browser’s engine
- Run your first JavaScript code in the browser console, in an HTML file, and in the terminal with Node.js
- Tell Java and JavaScript apart with examples, knowing they are different languages
- Check whether JavaScript is enabled in your browser and change the setting
Since this is the first lesson in the series, there are no prerequisites; basic computer and browser skills are enough. When you get to the variables topic, I recommend keeping the Differences Between Var, Let, and Const lesson open on the side.
What is JavaScript?
Short answer JavaScript is a high-level, interpreted, dynamically typed programming language that runs in the browser. It can access and change elements on the page, listen for user events, and send requests to a server.
The language dates back to 1995: this scripting language, written quickly by Brendan Eich for Netscape, took the name ECMAScript in 1997 with the ECMA-262 standard. Today the language standard is published by the TC39 committee with a new version every June; you can read the official text at tc39.es.
Let’s clear up a distinction that often gets confused: ECMAScript is the standard that defines the language’s rules; JavaScript is that standard brought to life in browser engines and Node.js. So a feature like Array.prototype.map is defined in the standard, and what runs it is the browser’s JavaScript engine. For a detailed explanation of the language and a reference list, the MDN Web Docs JavaScript page is the most reliable source.
Thinking about the language’s three layers together will make your life much easier in the lessons ahead:
| Layer | Role | Example |
|---|---|---|
| HTML | The skeleton of the content and page structure | Heading, paragraph, button |
| CSS | Appearance, color, layout | Text color, spacing, grid |
| JavaScript | Behavior and interaction | Reacting to clicks, updating data |
What is JavaScript used for, and where is it used?
Short answer When asked what JavaScript is used for, the answer falls under two headings: in the browser, form validation, content updates, animation, and exchanging data with a server; on the server, writing APIs and services. When we look at where it’s used, the same language also shows up in mobile app, desktop app, and embedded device projects.
Use in the browser (front end)
Changing a heading on the page, making tabs work, validating form fields instantly, implementing infinite scroll, and drawing charts are typical browser-side tasks. If content changes without the page reloading when the user presses a button, JavaScript is doing the work.
The words you’ll hear often in this area are DOM (the page’s object model), event, and fetch (pulling data from a server).
Use on the server (Node.js)
Node.js is a runtime that runs JavaScript outside the browser. With the same language you can write REST APIs, tools that process files, and real-time chat servers. That way, knowing a single language for both front end and back end gives small teams a serious speed advantage.
Mobile and desktop applications
On mobile, tools like React Native, and on desktop, frameworks like Electron use JavaScript. In these projects most of the codebase is shared; platform-specific parts are written separately.
Games, data visualization, and automation scripts are also among the language’s common use cases.
How does JavaScript work?
Short answer While parsing HTML, the browser downloads any script file it encounters and hands it to the JavaScript engine. The engine parses the code and converts it into an intermediate form, then runs it in order on a single thread.
How HTML, CSS, and JavaScript work together
The browser first reads the HTML and builds the page tree (DOM), then applies CSS and computes the appearance. When it encounters a <script> tag, it downloads and runs the JavaScript; that code can access the DOM and change the tree. The changed tree is repainted, and the user sees the new state.
That’s why the placement of the script tag matters: code that runs inside <head> may get null when it looks for an element that hasn’t been created yet. The fix is either to put the code just before </body> or to use the defer attribute.
How the JavaScript engine interprets code
Every browser has its own engine: V8 in Chrome, SpiderMonkey in Firefox, JavaScriptCore in Safari. The engine first parses the source code into a syntax tree, then produces an intermediate representation (bytecode). Hot code paths are sped up by being compiled straight to machine code with JIT (just-in-time compilation).
That’s why JavaScript behaves like both an interpreted and a compiled language; it starts out fast and gets faster on hot code paths. If there’s a syntax error, the engine throws an error without running the code at all.
Single thread and the event loop (beginner level)
JavaScript is single-threaded: only one block of code runs at a time. The browser carries out tasks like network requests or timers in the background; when a task finishes, the function to run is placed in a queue, and the event loop runs it once the main code is done.
This design keeps the page smooth without freezing. We’ll make the topic concrete later in the How to use javascript setInterval() and clearInterval()? lesson through timers.
Run your first JavaScript code
Short answer The fastest way is the browser console; if you want a persistent file, add a <script> to your HTML, and if you want to run it in the terminal, use Node.js. You don’t need to download JavaScript; it comes built into browsers, and you only install Node.js to run it in the terminal.
In the browser console (F12)
In Chrome, press F12 and open the Console tab, type the following lines at the prompt, and press Enter after each one:
document.title = "Merhaba JavaScript";
console.log("Konsol çalışıyor");
You’ll see the tab title change. The console is the fastest place to experiment, but anything you type there disappears when you refresh the page.
In an HTML file with the script tag
Save the following file as ilk-js.html and open it in your browser. When you click the button, the heading text is changed by JavaScript:
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="utf-8">
<title>İlk JavaScript</title>
</head>
<body>
<h1 id="baslik">Merhaba</h1>
<button id="dugme">Başlığı değiştir</button>
<script>
const baslik = document.querySelector("#baslik");
const dugme = document.querySelector("#dugme");
dugme.addEventListener("click", () => {
baslik.textContent = "JavaScript çalışıyor";
});
</script>
</body>
</html>
Because the script tag sits right before the </body> tag, it runs when the page elements are ready. If you move the code into <head>, you’re very likely to get a null error.
In the terminal with Node.js
If Node.js is installed, save the following file as ilk-js.js. This file runs on its own and doesn’t require extra packages or an internet connection:
const urunler = [
{ ad: "Klavye", fiyat: 750 },
{ ad: "Fare", fiyat: 420 },
{ ad: "Monitör", fiyat: 5400 }
];
function toplamFiyat(liste) {
let toplam = 0;
for (const urun of liste) {
toplam += urun.fiyat;
}
return toplam;
}
const toplam = toplamFiyat(urunler);
console.log("Ürün sayısı: " + urunler.length);
console.log("Toplam: " + toplam + " TL");
console.log("Ortalama: " + toplam / urunler.length + " TL");
Run the file from the terminal:
node ilk-js.js
The output looks like this:
Ürün sayısı: 3
Toplam: 6570 TL
Ortalama: 2190 TL
This example uses an array, an object, a function, and a for...of loop together. We’ll cover loops in detail in the Loops lesson and functions in the Functions lesson.
The difference between Java and JavaScript
Short answer Java and JavaScript are two separate languages that share only a similarity in name. Java is compiled and runs on a virtual machine, while JavaScript runs in a browser engine; their syntax and use cases are different.
| Feature | JavaScript | Java |
|---|---|---|
| Runtime environment | Browser engine (V8, etc.) and Node.js | JVM (Java Virtual Machine) |
| Type system | Dynamic; types are determined at runtime | Static; types are known at compile time |
| Execution model | Parsed and compiled with JIT | Compiled to bytecode first, then executed |
| File extension | .js, .mjs | .java |
| Typical use | Web front end, APIs, mobile, desktop | Enterprise back end, Android, large-scale systems |
| Entry point | The file runs from top to bottom | public static void main |
The only reason the names are similar is that in 1995 the new language was named close to Java for marketing purposes. Technically, there is no inheritance relationship between the two languages.
How to enable and disable JavaScript in the browser
Short answer JavaScript is enabled by default in browsers; to disable it, you just need to change the JavaScript permission in your site settings. When the setting is off, interactive elements on the site won’t work and the page appears only in its static form.
Enabling JavaScript in Chrome
- Open the three-dot menu in the top right of Chrome and go to Settings.
- Go to Privacy and security, then Site settings.
- Select JavaScript from the list.
- Under Default behavior, select Sites can use JavaScript.
- If you’re wondering how to disable JavaScript, just select Don’t allow sites to use JavaScript on the same screen.
If you want to set an exception for a single site, click the site information icon to the left of the address bar, open Site settings, and change the JavaScript permission for that site only. This approach is safer for testing a single site without affecting the entire browser. You can also verify the current steps on the Google Chrome Help page.
Enabling JavaScript on iPhone (Safari)
- Open the Settings app.
- Scroll down and tap Safari (on iOS 18 and later, it appears under Apps).
- Select Advanced.
- Turn on the JavaScript switch.
In iOS Safari, the JavaScript setting affects all sites; there’s no per-site option to enable or disable it. If you want to disable it, just turn the same switch off.
What happens if JavaScript is disabled
The page loads, but buttons, tabs, drop-down menus, and form validations don’t work. Some sites generate their content entirely with JavaScript, so they may appear empty or incomplete. For this reason, keeping JavaScript disabled in everyday use both breaks the experience and makes many sites unusable.
Is learning JavaScript hard? A learning roadmap
Short answer JavaScript’s basic syntax is easy to learn; the difficulty isn’t in the language itself but in using browser and asynchronous concepts together. If you move forward in regular, small steps, you’ll start writing working code in the first few weeks.
How do you learn JavaScript, and where do you start?
The most efficient order is this: first get familiar with page structure using HTML and CSS, then follow the lessons in this series in order from start to finish, reinforce each topic by reading the MDN JavaScript Guide, and write a small exercise every day. The roadmap below lays out this order step by step.
- Basic syntax: variables, types, operators. Reading the Differences Between Var, Let, and Const lesson early on when you get to variables keeps you from having to change your habits later.
- Flow control: for if/else and comparison operators, see Conditional Structures; for repetition, see Loops.
- Functions and arrays: start with Functions, then study array methods such as
map,filter, andreduce. - DOM and events: selecting elements from the page, changing text, listening for clicks.
- Asynchronous: fetching data from a server with
Promiseandasync/await.
Write and run a small example at each step. Writing the code yourself instead of watching a video noticeably speeds up learning.
Glossary of key terms for beginners
Short answer Knowing the standard English term behind a concept makes documentation much easier to read. The short list below collects the words you’ll run into most often throughout the series.
| Term | Also known as | Short description |
|---|---|---|
| Variable | binding | A named container that holds a value |
| Function | method | A block of code that performs a specific task |
| Array | list | An ordered list of values |
| Object | dictionary | A collection of key-value pairs |
| Condition | test | An expression that makes a true/false decision |
| Loop | iteration | A structure that runs code repeatedly |
| Event | listener | Triggers such as clicks and key presses |
| Scope | context | The area in which a variable is valid |
| Asynchronous | async | An operation that continues without waiting |
| Callback | handler | A function passed in to be run later |
| Promise | future value | A representation of an operation that will finish in the future |
| Debugging | DevTools | The process of finding the source of an error |
Common Mistakes
Short answer Most beginners fall into the same three mistakes: putting the script tag in the wrong place, not reading the error in the console, and thinking JavaScript is Java. Below are the symptom, cause, and fix for each one.
1. Putting the script tag in the wrong place
Symptom: You’re getting a “Cannot read properties of null” error in the console. Cause: The code runs before the HTML element it targets has been created. Fix: Move the script tag just before </body> or use the defer attribute.
2. Not reading the error in the console
Symptom: The code doesn’t work, but you don’t know why. Cause: The error message gives you the file name and line number; you’re moving forward by guessing without reading that information. Fix: Keep the F12 console open, read the first red line, and go to that line.
3. Confusing it with Java
Symptom: You search for a Java lesson, find a JavaScript example, and end up confused. Cause: The similar names also muddle search results. Fix: Type “JavaScript” when searching and check the file extension: .js is JavaScript, .java is Java.
4. Copying code and never changing it
Symptom: The example works, but you can’t solve a similar problem. Cause: You’re memorizing the code instead of building the logic. Fix: Change a value in the example, watch how the output changes, and write a small variation.
Frequently Asked Questions
What is JavaScript, and how do you turn it on?
JavaScript is a programming language that adds interactivity to web pages and is enabled by default in browsers. In Chrome, you can check the permission by going to the Settings menu, then Privacy and security, then Site settings, then JavaScript.
How is JavaScript used?
The most common use is adding code to an HTML file with the <script> tag. The browser console is used for quick experiments, and Node.js is used to run files in the terminal.
Is learning JavaScript hard?
The basic syntax is easy to learn; the real difficulty is in asynchronous flow and DOM concepts. If you make progress by writing small examples yourself, you can produce working code within the first few weeks.
What is the difference between Java and JavaScript?
The two languages share only a similar name; they have no technical connection. Java is compiled and runs on the JVM, while JavaScript runs in a browser engine or Node.js and is dynamically typed.
How do you turn on JavaScript on iPhone?
In the Settings app, go to Safari, then Advanced, and turn on the JavaScript switch. On iOS 18 and later, Safari settings live under the Apps heading in the Settings menu. This setting applies to all sites; it can’t be set per site.
What happens if JavaScript is turned off?
The page opens, but buttons, menus, and form controls don’t work. Sites that build their content entirely with JavaScript may appear empty, so turning the setting off permanently is not recommended.
Summary and Next Lesson: var, let, const
- JavaScript is the programming language that adds behavior to HTML’s structure and CSS’s appearance.
- In the browser, an engine (V8, SpiderMonkey, JavaScriptCore) parses the code, speeds it up with JIT, and runs it on a single thread.
- You can try your first code in three places: the console, a script tag inside HTML, and Node.js.
- Java and JavaScript are different languages; the name similarity is a marketing artifact.
- You can turn JavaScript on and off in your browser settings, and in Chrome you can define an exception for a single site.
In the next lesson of the series, we’ll look at the ways to declare variables, namely the differences between var, let, and const, and their scoping behavior; to prepare, you can take a look at the Differences Between Var, Let and Const lesson. After that, we’ll continue with the Conditional Statements lesson.
Resources
- MDN Web Docs – JavaScript (developer.mozilla.org) MDN%20Web%20Docs%20–%20JavaScript%20(developer.mozilla.org)
- ECMAScript language standard (tc39.es) ECMAScript%20dil%20standardı%20(tc39.es)
- Google Chrome Help – JavaScript permission in site settings Google%20Chrome%20Yardım%20–%20site%20ayarlarında%20JavaScript%20izni
Lesson complete · 1 / 1
You've finished this lesson
The next lesson in the series is in the works. Subscribe to the channel so you don't miss it when it's published.
Share it if it helped


