Variables — let and const
עמוד זה דורש דפדפן עדכני (תומך ב-SharedArrayBuffer). אנא עדכן את Chrome, Edge, Firefox או Safari לגרסה העדכנית ביותר.
English
A variable is a named box
- A variable stores a value and gives it a name, so you can use it again later.
letmakes a box you can change.constmakes a box that must stay the same (a constant).
English
let age = 15; // a value that may change
const name = "Ada"; // a value that won't
console.log(name, age); // → Ada 15
English
Change a let with a new value
- Assign again —
count = count + 1— to update alet. count++is a handy shortcut for "add 1 tocount".

English
let count = 0;
count = count + 1;
count++;
console.log(count); // → 2
חקור
Watch the boxes change
A variable is a named box. let can be changed; const stays fixed.
English
Watch out
- A
constcannot be reassigned:const x = 1; x = 2;throws an error. - Good habit: use
constby default, and reach forletonly when the value truly changes.
English
Common mistakes
- Use
constfor values that never change,letfor those that do. - Declare a variable before you use it.
English
Now you try
- Use
letorconstto store values. - Press Check answer to test it.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Store the text Cairo in a const נקרא city, then log city.
לחץ על הרץ כדי לראות את התוצא כאן.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
let w = 4 וגם let h = 3 are the width and height. Work out the area (w * h) and log it (it is 12).
לחץ על הרץ כדי לראות את התוצא כאן.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Make a let total = 10, add 5 to it, then log total (it is 15).
לחץ על הרץ כדי לראות את התוצא כאן.