QA Learning Journal #2: Understanding Variables — var, let & const
After understanding how JavaScript runs inside the V8 Engine, the next logical step is to understand how we actually write JavaScript.
QA Learning Journal #2: Understanding Variables — var, let & const
After understanding how JavaScript runs inside the V8 Engine, the next logical step is to understand how we actually write JavaScript.
Everything starts with variables.
Whether you’re storing a user’s name, the result of a calculation, or the status of an API call, variables are the building blocks of every JavaScript program.
Let’s explore the three ways JavaScript allows us to declare variables.
What is a Variable?
Think of a variable as a label attached to a box where JavaScript stores a value.
let city = "Delhi";
Here,
city→ variable name"Delhi"→ value stored inside it, also called as literals
Whenever we use city, JavaScript knows where to find the value.
JavaScript gives us three keywords
varletconst
Although all three create variables, they behave differently.
var
var was the original way of declaring variables.
var age = 25;
It can be
✔ Redeclared
✔ Reassigned
Because of its function scope and hoisting behavior, it can sometimes produce unexpected results.
Today, it’s mostly seen in older JavaScript code.
let
let age = 25;
let allows you to update a value later.
let score = 80;
score = 90;
This is useful when data changes during execution.
const
const pi = 3.14;
const cannot be reassigned.
const pi = 3.14;
pi = 3.1415; // Error
It’s perfect for values that should remain constant.
When should we use each?
A simple rule I’m following while learning:
✅ Use const by default.
✅ Use let only if the value needs to change.
❌ Avoid var unless working with legacy code.
My Key Takeaways
- Variables store values.
- JavaScript offers three ways to declare variables.
constis generally the safest choice.letis useful when values change.varstill exists but is less common in modern JavaScript.
What’s Next?
In my next article, I’ll continue exploring JavaScript fundamentals by understanding data types and operators, the two concepts that help JavaScript know what kind of data it’s working with and what operations it can perform on it.
메타데이터
- post_id
- 6beb9edc73fd
- slug
- qa-learning-journal-2-understanding-variables-var-let-const-6beb9edc73fd
- url
- https://medium.com/@priti.jain84/qa-learning-journal-2-understanding-variables-var-let-const-6beb9edc73fd
- canonical_url
- https://medium.com/@priti.jain84/qa-learning-journal-2-understanding-variables-var-let-const-6beb9edc73fd
- author_url
- https://medium.com/@priti.jain84
- status
- ok
- fetched_at
- 2026-07-24 19:13:54