A variable is a name that holds a value. Modern JavaScript uses two keywords: const for values that will not change, and let for values that will.
const name = "Anita";
let score = 70;
score = score + 10;
console.log(name, score);
Output:
Anita 80
Trying to change a const causes an error, which protects you from accidents. Use const by default and let only when needed. (You will also see the older var in old code; avoid it in new code.)
The basic types
| Type | Example | Notes |
|---|---|---|
| number | 42, 3.14 | one type for whole and decimal numbers |
| string | "Pokhara" | text; single or double quotes |
| boolean | true, false | yes/no values (lower case) |
| undefined | undefined | a variable with no value yet |
| null | null | deliberately empty |
console.log(typeof 42);
console.log(typeof "hello");
console.log(typeof true);
console.log(typeof undefined);
Output:
number
string
boolean
undefined
Template strings
Wrap text in backticks ` and put values inside ${ } to build sentences.
const city = "Butwal";
const year = 2026;
console.log(`I live in ${city} and it is ${year}`);
console.log(`2 + 3 = ${2 + 3}`);
Output:
I live in Butwal and it is 2026
2 + 3 = 5
Turning text into numbers
const text = "25";
console.log(text + 5);
console.log(Number(text) + 5);
Output:
255
30
The first line joins text ("25" and "5" side by side). The second converts to a number first. Watching for this difference prevents many bugs.
Try it yourself
- Store your name and age in variables and print a sentence with a template string.
- Make a
constfor a price and aletfor a quantity, then print the total. - Print the type of each variable.
Next lesson: decisions with if.

Comments
Loading comments…