Mamun Labs Learn
JourneyGlossary
esc
  • Try “map”, “flexbox” or “state”.
Log in
Start learning
Phase 2 · 1 / 12Values and variables
Phase 2JavaScript core
12 topics · 4–6 wks
  1. 1Values and variables
  2. 2Strings and numbers
  3. 3Making decisions with if
  4. 4Loops
  5. 5Functions in, values out
  6. 6Arrays
  7. 7Objects
  8. 8Arrays and map
  9. 9filter and find
  10. 10reduceoptional
  11. 11Scope
  12. 12Reading error messages
JourneyPhase 2Values and variables
01 / 09Overview

Values and variables

You'll learn to store values in variables with const and let, and to say what a variable holds.

Why it mattersEvery program, from a tip calculator to a React app, keeps its data in named variables.
about 60 min
02 / 09

Watch & read

Start with the required ones. The others are there when you need them.

Article
Variablesjavascript.info · 15 min · English
MMamun's noteRead the whole page. It is short and clear. When it mentions `var`, just know it is the old way.
Video
Modern JavaScript Tutorial #2: Syntax basics and typesYouTube · Net Ninja · 13 min · English
MMamun's noteWatch 7:42–20:37 only, on variables, constants and data types. Stop when string methods start; that is the next topic.
VideoOptional
JavaScript Bangla tutorial #07: the let keywordYouTube · Learn with Sumit · 22 min · Bangla
MMamun's noteIn Bangla. Sumit explains `let` and why it replaced `var`. Watch it if the English page felt fast.
ArticleOptional
Data typesjavascript.info · 10 min · English
MMamun's noteRead about number, string and boolean, and the `typeof` part at the end. Skip BigInt and Symbol.
03 / 09

Explanation

You want your program to remember things: a name, a balance, a score. To do that, you give each piece of data a name.

A piece of data is called a value: "Nusrat", 500, true. A name that holds a value is called a variable. Think of your bKash app. The balance shown on screen is the value. "Balance" is the label that always points to it, even when the amount changes.

const name = "Nusrat";
let balance = 500;
balance = balance - 120;
console.log(balance); // 380

const makes a variable you will not point to a new value. let makes one you can change later. Use const by default, and switch to let only when the value must change. Then, when you read const, you know at a glance that it stays the same. You will also see var in old code. It is the old way to write let; don't use it in new code.

The = sign does not mean "equal" here. It means "put the value on the right into the name on the left". So balance = balance - 120 reads: take the balance, subtract 120, store the result back in balance.

Values come in kinds, called types. Text in quotes is a string, 500 is a number, and true or false is a boolean. typeof tells you the type: typeof 500 is "number".

People often write const and then try to change it. JavaScript stops with TypeError: Assignment to constant variable. That is not a disaster: it means the value really needs let.

Good names help too. balance is better than b, and studentCount is better than x. Names can't have spaces, so join words like studentCount.

When you read code, find each variable and ask two questions: what does it hold now, and can it change?

Words to recognise
valuevariableconstlet=stringnumberbooleantypeof
04 / 09

Code tour

Click a line number with a ring to read the note for that line.

script.js5 notes
const name = "Nusrat";
Mentor note · line 1
const creates a variable called name and puts the string "Nusrat" in it. This name will not change.
let balance = 500;
3console.log(name, balance);
4
balance = balance - 120;
6console.log(balance);
7// 380
8
9const city = "Dhaka";
// city = "Sylhet"; would stop with a TypeError
11
console.log(typeof balance);
13// "number"
05 / 09

Practice

Short drills. Take your time and read the code before you answer.

DrillPredict1 / 2
1let score = 10;
2score = score + 5;
3const bonus = 2;
4console.log(score * bonus);
What does this print?
DrillFind the bug2 / 2
You pay 100 taka and then 50 taka. balance should end at 350. Fix the code so both checks pass.
1
2
3
Try 1 of 3 · solution unlocks after 3
06 / 09

Quick check

3 questions. Each one explains itself after you answer.

  1. 1 / 3After let score = 10; score = score + 5;, what is score?
  2. 2 / 3What happens with const city = "Dhaka"; city = "Sylhet";?
  3. 3 / 3What is typeof "500"?
07 / 09

Explain it back

Only you can see this. Log in to keep it.0 words
08 / 09

How confident are you with Values and variables?

09 / 09

Done

You can now
Read a few lines of code and say what each variable holds at the end.
Next: Strings and numbers Back to Phase 2
On this page
  1. 01Values and variables
  2. 02Watch & read
  3. 03Explanation
  4. 04Code tour
  5. 05Practice
  6. 06Quick check
  7. 07Explain it back
  8. 08Confidence
  9. 09Done
Up next · 02 / 09Watch & read
Mamun Labs LearnFound a mistake on this page? Tell Mamun.
Mamun Labs Learn
JourneyGlossary
esc
  • Try “map”, “flexbox” or “state”.
Log in
Start learning
Log in to save your progress. Everything here works without an account.Log in to save progressLog in
Phase 2JavaScript core
12 topics · 4–6 wks
  1. 1Values and variables
  2. 2Strings and numbers
  3. 3Making decisions with if
  4. 4Loops
  5. 5Functions in, values out
  6. 6Arrays
  7. 7Objects
  8. 8Arrays and map
  9. 9filter and find
  10. 10reduceoptional
  11. 11Scope
  12. 12Reading error messages
JourneyPhase 2Values and variables
01 / 09Overview

Values and variables

You'll learn to store values in variables with const and let, and to say what a variable holds.

Why it mattersEvery program, from a tip calculator to a React app, keeps its data in named variables.
about 60 min
02 / 09

Watch & read

Start with the required ones. The others are there when you need them.

Article
Variablesjavascript.info · 15 min · English
MMamun's noteRead the whole page. It is short and clear. When it mentions `var`, just know it is the old way.
Video
Modern JavaScript Tutorial #2: Syntax basics and typesYouTube · Net Ninja · 13 min · English
MMamun's noteWatch 7:42–20:37 only, on variables, constants and data types. Stop when string methods start; that is the next topic.
VideoOptional
JavaScript Bangla tutorial #07: the let keywordYouTube · Learn with Sumit · 22 min · Bangla
MMamun's noteIn Bangla. Sumit explains `let` and why it replaced `var`. Watch it if the English page felt fast.
ArticleOptional
Data typesjavascript.info · 10 min · English
MMamun's noteRead about number, string and boolean, and the `typeof` part at the end. Skip BigInt and Symbol.
03 / 09

Explanation

You want your program to remember things: a name, a balance, a score. To do that, you give each piece of data a name.

A piece of data is called a value: "Nusrat", 500, true. A name that holds a value is called a variable. Think of your bKash app. The balance shown on screen is the value. "Balance" is the label that always points to it, even when the amount changes.

const name = "Nusrat";
let balance = 500;
balance = balance - 120;
console.log(balance); // 380

const makes a variable you will not point to a new value. let makes one you can change later. Use const by default, and switch to let only when the value must change. Then, when you read const, you know at a glance that it stays the same. You will also see var in old code. It is the old way to write let; don't use it in new code.

The = sign does not mean "equal" here. It means "put the value on the right into the name on the left". So balance = balance - 120 reads: take the balance, subtract 120, store the result back in balance.

Values come in kinds, called types. Text in quotes is a string, 500 is a number, and true or false is a boolean. typeof tells you the type: typeof 500 is "number".

People often write const and then try to change it. JavaScript stops with TypeError: Assignment to constant variable. That is not a disaster: it means the value really needs let.

Good names help too. balance is better than b, and studentCount is better than x. Names can't have spaces, so join words like studentCount.

When you read code, find each variable and ask two questions: what does it hold now, and can it change?

Words to recognise
valuevariableconstlet=stringnumberbooleantypeof
04 / 09

Code tour

Click a line number with a ring to read the note for that line.

script.js5 notes
const name = "Nusrat";
Mentor note · line 1
const creates a variable called name and puts the string "Nusrat" in it. This name will not change.
let balance = 500;
3console.log(name, balance);
4
balance = balance - 120;
6console.log(balance);
7// 380
8
9const city = "Dhaka";
// city = "Sylhet"; would stop with a TypeError
11
console.log(typeof balance);
13// "number"
05 / 09

Practice

Short drills. Take your time and read the code before you answer.

DrillPredict1 / 2
1let score = 10;
2score = score + 5;
3const bonus = 2;
4console.log(score * bonus);
What does this print?
DrillFind the bug2 / 2
You pay 100 taka and then 50 taka. balance should end at 350. Fix the code so both checks pass.
1
2
3
Try 1 of 3 · solution unlocks after 3
06 / 09

Quick check

3 questions. Each one explains itself after you answer.

  1. 1 / 3After let score = 10; score = score + 5;, what is score?
  2. 2 / 3What happens with const city = "Dhaka"; city = "Sylhet";?
  3. 3 / 3What is typeof "500"?
07 / 09

Explain it back

Only you can see this. Log in to keep it.0 words
08 / 09

How confident are you with Values and variables?

09 / 09

Done

You can now
Read a few lines of code and say what each variable holds at the end.
Next: Strings and numbers Back to Phase 2
On this page
  1. 01Values and variables
  2. 02Watch & read
  3. 03Explanation
  4. 04Code tour
  5. 05Practice
  6. 06Quick check
  7. 07Explain it back
  8. 08Confidence
  9. 09Done
Up next · 02 / 09Watch & read

You want your program to remember things: a name, a balance, a score. To do that, you give each piece of data a name.

A piece of data is called a value: "Nusrat", 500, true. A name that holds a value is called a variable. Think of your bKash app. The balance shown on screen is the value. "Balance" is the label that always points to it, even when the amount changes.

const name = "Nusrat";
let balance = 500;
balance = balance - 120;
console.log(balance); // 380

const makes a variable you will not point to a new value. let makes one you can change later. Use const by default, and switch to let only when the value must change. Then, when you read const, you know at a glance that it stays the same. You will also see var in old code. It is the old way to write let; don't use it in new code.

The = sign does not mean "equal" here. It means "put the value on the right into the name on the left". So balance = balance - 120 reads: take the balance, subtract 120, store the result back in balance.

Values come in kinds, called types. Text in quotes is a string, 500 is a number, and true or false is a boolean. typeof tells you the type: typeof 500 is "number".

People often write const and then try to change it. JavaScript stops with TypeError: Assignment to constant variable. That is not a disaster: it means the value really needs let.

Good names help too. balance is better than b, and studentCount is better than x. Names can't have spaces, so join words like studentCount.

When you read code, find each variable and ask two questions: what does it hold now, and can it change?

Words to recognise
valuevariableconstlet=stringnumberbooleantypeof

You want your program to remember things: a name, a balance, a score. To do that, you give each piece of data a name.

A piece of data is called a value: "Nusrat", 500, true. A name that holds a value is called a variable. Think of your bKash app. The balance shown on screen is the value. "Balance" is the label that always points to it, even when the amount changes.

const name = "Nusrat";
let balance = 500;
balance = balance - 120;
console.log(balance); // 380

const makes a variable you will not point to a new value. let makes one you can change later. Use const by default, and switch to let only when the value must change. Then, when you read const, you know at a glance that it stays the same. You will also see var in old code. It is the old way to write let; don't use it in new code.

The = sign does not mean "equal" here. It means "put the value on the right into the name on the left". So balance = balance - 120 reads: take the balance, subtract 120, store the result back in balance.

Values come in kinds, called types. Text in quotes is a string, 500 is a number, and true or false is a boolean. typeof tells you the type: typeof 500 is "number".

People often write const and then try to change it. JavaScript stops with TypeError: Assignment to constant variable. That is not a disaster: it means the value really needs let.

Good names help too. balance is better than b, and studentCount is better than x. Names can't have spaces, so join words like studentCount.

When you read code, find each variable and ask two questions: what does it hold now, and can it change?

Words to recognise
valuevariableconstlet=stringnumberbooleantypeof