JavaScript for Beginners
A free beginner JavaScript course. Ten short lessons take you from console.log to a working shopping-cart library, covering functions, arrays and objects, array methods, closures and how a web page is built. Every lesson has code that runs and is checked in your browser.
10 lessons 3 hours of lessons 76 practice questions FreeEvery lesson, in order
Planned as 6 weeks at 4 sessions a week, about 30 minutes each. Each lesson opens here in full; in BiliMind your answers are marked and your flashcards come back before you forget them.
JavaScript for Beginners
Start here The finish lineYour first JavaScript
14 minRun code, print with console.log, and know the basic value types.
- `console.log(value)` prints a value on its own line.
- The basic types are number, string, boolean, undefined and null; `typeof` names the type.
- Backtick strings (template literals) can embed values with `${...}`.
- With `+`, any string makes the result a string: `"5" + 5` is `"55"`.
Variables and operators
17 minStore values with const and let, calculate, compare with ===, and build text with template literals.
- Use `const` by default and `let` when a value must change; avoid `var`.
- Compare with `===` and `!==`; `==` converts types and surprises.
- `/` is always decimal; round money with `Math.round(x * 100) / 100`.
- Template literals (backticks and `${}`) build text from values.
Functions
18 minWrite functions with parameters and return values, in declaration and arrow form.
- A function takes parameters and `return`s a value; with no `return` it gives back `undefined`.
- Arrow functions `(a, b) => a + b` are a short form; add braces and `return` for several statements.
- Default parameters (`greeting = "Hello"`) fill in missing arguments.
- Functions are values: you can pass them to other functions.
Decisions and loops
18 minBranch with if and the ternary, and repeat with for, while and for...of.
- `if / else if / else` runs the first true branch; narrowest test first.
- `0`, `""`, `null`, `undefined`, `NaN` and `false` are falsy; empty arrays and objects are truthy.
- `for...of` visits each item; the classic `for` gives you the index; `while` repeats on a condition.
- Watch `<` versus `<=`: off-by-one bugs live there.
Arrays
18 minStore ordered lists, add and remove items, copy with spread, and unpack with destructuring.
- Arrays are ordered lists indexed from 0; `length` is the count.
- `push`, `pop`, `shift`, `unshift` and `splice` change the array; `slice` and spread copy.
- Arrays are shared by reference: `const b = a` is not a copy.
- Destructuring (`const [a, b] = arr`) unpacks by position.
Objects
18 minGroup related values with objects, read and change properties, loop over keys, and convert to JSON.
- An object holds named properties: `obj.name`, or `obj[key]` when the name is in a variable.
- `Object.keys`, `values` and `entries` let you loop over an object.
- Arrays of objects are the usual shape of real data.
- Objects are shared by reference: copy with `{ ...obj }`.
Transform and summarize lists with the array methods you will use every day.
- `map` transforms each item; `filter` keeps some; `find` returns the first match; `reduce` folds a list into one value.
- These methods return new values and chain left to right.
- `sort` changes the array and sorts as text unless you give `(a, b) => a - b`.
- Always give `reduce` a starting value.
Scope and closures
18 minKnow where variables live, and use closures to make functions that remember.
- `const` and `let` are block-scoped; a function sees the scopes around it, never the reverse.
- A closure is a function plus the variables it remembered from where it was created.
- Closures give you private state and functions made to order.
- Use `let`/`const`, not `var`, so each loop round gets its own variable.
The DOM and events
20 minSee a web page as a tree you can read and change from JavaScript, and build the markup it works on.
- The DOM is the page as a tree of objects that JavaScript can read and change.
- `querySelector` finds elements with CSS selectors; `textContent`, `createElement` and `append` change them.
- `addEventListener("click", fn)` runs your function on an event.
- Keep the logic in plain functions of data, so it is simple to test, and keep the DOM code thin.
Build a small cart library from pure functions: add, remove, total and a text summary.
- Pure functions take data and return new data; they never change their inputs.
- `map`, `filter`, `reduce` and spread build new arrays without mutation.
- Build later functions on earlier ones instead of repeating logic.
- Decide the empty-case behaviour up front and test it.
01Do I need to install anything?
No. The code runs in your browser. Later, to build real pages on your own computer, you only need a text editor and a web browser.
02Is JavaScript the same as Java?
No. They are different languages that share part of a name for historical reasons.
03Does this teach modern JavaScript?
Yes: const and let, arrow functions, template literals, destructuring, spread and the array methods used in current code.
04Will I learn to build web pages?
You learn the language and how the DOM works, and you build the HTML structure of a small page. HTML and CSS in depth are the natural next step.
05What about frameworks like React?
Learn the language first. Frameworks are built from exactly the functions, arrays, objects and closures in this course.
Study it properly, free
Start the course in BiliMind and it's yours: 76 questions marked as you go, 44 flashcards on spaced review, a plan around your week, and an assistant that can change any lesson.
Facts checked against: MDN: JavaScript, ECMAScript language specification.