
📎 This article includes 2 downloadable practice files ↓
Variables hold values. Modern JavaScript uses const (can’t be reassigned) and let (can); avoid the old var.
const customer = "Sharma Traders";
let qty = 12;
const amount = qty * 60;
console.log(`${customer}: ${qty} x Rs 60 = Rs ${amount}`); // template literal
Types
Numbers (one type for integers and decimals), strings, booleans (true/false), plus null, undefined, objects and arrays. typeof tells you which.
Indian formatting
(1234567).toLocaleString("en-IN") gives 12,34,567.
String methods
" ravi kumar ".trim().toUpperCase(); // "RAVI KUMAR"
"INV-2026-0145".split("-"); // ["INV", "2026", "0145"]
"Sharma Traders".includes("Traders"); // true
⚠️ “5” + 3 is “53” (text joining) but “5” * 3 is 15. Convert text to numbers with Number(“5”) before maths.
Practice
Run the script, then change the quantity and rate.
📎 Practice files for this article
⬇ Download all 2 files (ZIP · 639 B)
- 📄js-02-variables.jsLesson code file.⬇ JS · 422 B
- 📄js-02-variables-output.txtOutput from our test run.⬇ TXT · 122 B
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
✨ Ask AI about this article
Stuck on a step? Ask a question and the AI answers using this article.
Free · AI can be wrong