Variables — Complete Guide
Variables — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of JavaScript Tutorial on Toolliyo Academy.
On this page
JavaScript Tutorial · Lesson 3 of 100
Variables
Basics → Objects & data → Async & DOM → Advanced → Tools → Projects
Beginner · 1 — Learn by example · ~6 min · JS Tutorial — Basics
What is this?
Variables are named boxes that store values — a name, a number, true/false, or a list. You create them with let or const, then use the name later instead of repeating the value.
Why should you care?
When a user logs in, you store their name in a variable and show it on every page. When the price changes, you update one variable instead of hunting through the whole file.
See it live — copy this example
Paste into an HTML file or the browser console (F12). Use Run below when the live editor is available.
let userName = "Priya";
const maxLoginAttempts = 3;
let score = 10;
score = score + 5;
console.log(userName, score, maxLoginAttempts);
Run Example »
Edit the code below and click Run to see the result in Toolliyo’s live editor.
What happened?
- let means the value can change later.
- const means you will not reassign the variable (the name stays fixed).
- userName and score are let; maxLoginAttempts is const.
Practice next
- Run the example in the browser console.
- Change userName to your name and run again.
- Increment score several times with score = score + 1.
- Swap let for const on score and see which assignments fail.
- Add a boolean isLoggedIn variable and log it with the others.
Remember
let = value can change const = binding stays fixed Give variables clear names like userName
ScriptVerse user session
After login, the app stores displayName and role in variables used across navbar, profile, and admin panels.
Outcome: One source of truth for user state avoids repeating API calls on every component.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!