
Variables and Data Types in JavaScript
Every program you will ever write starts with the same move: storing information so you can use it later. A user's name, a score, a shopping cart total, a…
Read tutorialGet comfortable with the building blocks behind JavaScript programs: values, variables, collections, comparisons, decisions, and repetition.
Tutorials
Follow these lessons in order, or jump directly to the topic you need.

Every program you will ever write starts with the same move: storing information so you can use it later. A user's name, a score, a shopping cart total, a…
Read tutorial
You've learned how to store values in variables. Now it's time to make those values do something. JavaScript operators are the verbs of your code—they add,…
Read tutorial
A website is mostly text doing work: a signup form checking an email address, a search bar cleaning up what a user typed, a dashboard greeting someone by…
Read tutorial
A variable can hold one value—and that value can be a collection holding many related values. JavaScript arrays and objects are how you build those…
Read tutorial
Every program you write has to react to the world around it. A login form needs to say "Welcome back" to one person and "Invalid password" to another. A…
Read tutorial
Five console.log statements will print five numbers. Fifty will print fifty. Five hundred will print five hundred—if you have the patience to write them…
Read tutorial
You know how to build an array. Now comes the part where every beginner hits the same wall: you need to change the values, keep only some of them, or total…
Read tutorial
You already know how to declare a variable. You've probably written let score = 0 or const userName = "Alex" and moved on. But then you open an older…
Read tutorial
Now you're stuck on a question that feels bigger than the error itself: do you change the const to let, or do you rewrite the line that's failing? The…
Read tutorial
You can loop over an array three different ways, and they all look nearly identical when you write them. So which one should you use?
Read tutorial
You can write an if/else statement. You know where the braces go and what console.log does. But when the condition gets even slightly tricky, you hesitate.…
Read tutorial
You have text in a variable. You want to check it, cut it, clean it, or change it. But which method does which—and what does each one give you back?
Read tutorial
You have probably already written code like this: a cartTotal here, a userName there, an isLoggedIn flag somewhere else. It works, right up until you…
Read tutorial
Two equals signs and three equals signs look like a typo. They are not. They are two different questions, and one of them lies to you politely.
Read tutorial
You copy a method into a new variable, call it, and get undefined instead of the name you expected. Nothing in the object changed. Nothing in the function…
Read tutorial
You have a list of tags with duplicates, or you want to count visits per user object, and your array or plain object starts fighting you. Here are the two…
Read tutorial
You write a variable inside a function, log it, and it prints perfectly. You move that same console.log two lines down, outside the function, and suddenly…
Read tutorial
A function can outlive the variables it was born next to. That sentence sounds wrong until you run it.
Read tutorial
That is the normal first experience with recursion. The function calls itself, the answer appears, and somewhere in the middle your mental model goes dark.…
Read tutorial
Three lines, three property reads, three variables. It works, and it is honest code. But then you see a modern codebase do the same job in one line, with…
Read tutorial
One bad line can take down everything after it. Here is how to catch that failure at the exact point it happens, and how to throw your own when a function…
Read tutorial
A condition does not ask whether a value is true. It asks what that value becomes when JavaScript forces it into a yes-or-no decision.
Read tutorial
You log a value from an API or from localStorage, and it looks exactly like an object. You can see the keys. You can see the values. So you try to read a…
Read tutorial
You log three things in the console. A variable you declared but never filled in. A property you hoped was on an object. A function call that was supposed…
Read tutorial
You type new Date() into the console and get back a long string with a time zone name you never asked for. You type Date.now() and get a big number. Same…
Read tutorial
You start with a simple check. Does this input contain a dash? You reach for includes(). Then the input changes shape, and suddenly you have five if…
Read tutorial