A variable is a name that refers to a value stored in memory. You assign a value to it, read it later by name and, unless it is declared constant, replace it with a different value.
Why it matters
Variables are the basic building block of every program. Good names make code self-explanatory, and a variable's scope, the part of the program where it is visible, determines what can change it. Many bugs come from a variable holding a value other than what the programmer expected.
Example
const taxRate = 0.18; // constant: cannot be reassigned
let total = 0; // can change
total = total + 100 * (1 + taxRate);
console.log(total); // 118
taxRate is declared with const, so reassigning it raises an error, while total is declared with let and updated.
Common mistakes
- Using vague names like
xordatafor values with real meaning. - Relying on global variables that any function can modify.
- Mixing up the value with a reference; in many languages two variables can point to the same list or object.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.