Free beginner tutorial

JavaScript Tutorial for Beginners

JavaScript adds behavior and interactivity to web pages. Start with values and variables, then learn how to organize reusable instructions and respond to user actions.

JavaScript runs in the browser and can update page content, respond to clicks, validate forms and work with data. It works alongside HTML for structure and CSS for presentation.

Add JavaScript to a web page

Link an external JavaScript file with defer so the browser runs it after parsing the HTML:

<script src="script.js" defer></script>

Start with these JavaScript topics

Variables and valuesStore text, numbers and other data. ScopeLearn where variables can be read and changed. Operators and expressionsCalculate values, compare data and combine conditions. Type conversion and coercionConvert values deliberately and recognize automatic type changes. Strings and textCombine, search and clean text in JavaScript. JSON dataParse and create JSON text with safe error handling. FunctionsGroup reusable instructions into named actions. ClassesCreate similar objects with shared setup and behavior.ModulesOrganize code across files with import and export. DOM and eventsFind page elements and respond to user interaction.ConditionalsChoose what your code does based on a condition. LoopsRepeat steps with for, while and for...of. Dates and timeCreate, compare and format dates for people. Math and random numbersRound values, compare numbers and generate simple random integers. Arrays and array methodsTransform, filter, search and summarize ordered lists. ObjectsGroup related information into named properties. Map and SetStore key-value entries or collections of unique values. Async and fetchRequest data and handle asynchronous results.PromisesHandle asynchronous results and coordinate independent tasks. Debugging and errorsRead error messages and handle failures clearly. Form validationUse built-in constraints and JavaScript to explain input errors. Browser storageSave small preferences with localStorage and sessionStorage. Regular expressionsMatch, check and extract patterns in text.
Open your browser's developer tools and use the Console to see messages and diagnose JavaScript errors.

A practical order for learning JavaScript

Begin with variables and values, then learn scope, operators and expressions, type conversion, and Math methods before working with strings and JSON data. Use conditionals to make decisions and loops to repeat work. Then learn arrays and methods such as map, filter, find and reduce, objects, Map and Set collections, functions and classes, then modules to organize code across files, before using the DOM and events to make a page interactive. Learn asynchronous code for data requests and Promises to handle results and coordinate tasks. Then learn debugging and error handling, and finish by practicing form validation.

Do I need HTML and CSS before JavaScript?

Basic HTML makes it easier to understand the elements JavaScript can change, and basic CSS helps you style those changes. You can learn JavaScript alongside them; the HTML tutorial and CSS tutorial provide the page structure and styling foundations.

Where can I run JavaScript examples?

Save a JavaScript file next to a small HTML page, link it with a script element using defer, and open the page in your browser. Use the developer tools Console to view output and error messages.