Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

JS
JavaScript
0/12 completed
Beginner
What is JavaScript?Variables and data typesOperators and expressionsMaking decisions: if and switchLoops
Intermediate
FunctionsArrays and array methodsObjects
Advanced
Scope and closuresClasses and OOPPromises and async/await
Pro
The event loop
Tracks / JavaScript / Beginner

Variables and data types

A variable is a named box that stores a value so you can use it later. Programs use variables to remember things: a user's name, the score in a game, the items in a cart.

Creating variables: let and const

JavaScript · editable
  • let creates a variable whose value can change.
  • const creates a variable that cannot be reassigned.

Try adding playerName = 'Rahul'; at the end and run it. You'll get an error, because const protects the value.

Rule of thumb: use const by default. Switch to let only when you need to reassign. You may see var in older code. It behaves differently, so avoid it in new code.

Naming rules

  • Names can contain letters, digits, _ and $, but can't start with a digit.
  • They are case-sensitive: age and Age are different.
  • Use camelCase for multi-word names: totalPrice, isLoggedIn.

Data types

Every value has a type. You can check it with typeof.

JavaScript · editable
Type Example Used for
number 42, -7, 3.14 Counting and maths
string 'hi', "hi", `hi` Text
boolean true, false Yes/no decisions
undefined undefined "No value assigned yet"
null null "Intentionally empty"
object { name: 'Asha' }, [1, 2] Groups of values

Strings and template literals

Backticks (`) let you put variables directly inside text with ${...}. These are called template literals.

JavaScript · editable

Converting between types

JavaScript · editable

Practice

Create variables for a product: name, price and inStock (a boolean). Then print a sentence like Laptop costs $899 — in stock: true using a template literal.

JavaScript · editable
✎ Check your understanding

1.Which keyword should you use for a value that never gets reassigned?

2.What is '5' + 3?

← What is JavaScript?