Tutorials JavaScript Tutorial

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

BasicsObjects & dataAsync & DOMAdvancedToolsProjects

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.

Code
Result

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

  1. Run the example in the browser console.
  2. Change userName to your name and run again.
  3. Increment score several times with score = score + 1.
  4. Swap let for const on score and see which assignments fail.
  5. 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.

Mid PDF Detailed
What are variables in JavaScript?
Short answer: Variables are containers to store data. let age = 25; Variables are containers to store data. Example code let age = 25; Variables are containers to store data. Example: let age = 25; Variables are containe…
Junior PDF Detailed
What is the difference between inline-block and block?
Short answer: block elements take full width and start on a new line. inline-block behaves like inline (stays in the same line) but allows setting width, height, margin, and padding. Example code .block { display: block;…
Mid PDF Detailed
Explain the difference between HTML4 and HTML5.
Short answer: HTML5 is the modern evolution of HTML4, introducing better structure, multimedia support, and APIs. Explain a bit more Follow me on LinkedIn: HTML4 mainly focused on document markup, while HTML5 focuses on…
Mid PDF Detailed
Class selector: Targets elements with a class.?
Short answer: .highlight { background: yellow; } .highlight { background: yellow; } .highlight { background: yellow; } .highlight { background: yellow; } .highlight { background: yellow; } .highlight { background: yellow…
Mid PDF Detailed
How does the browser parse and render HTML?
Short answer: When a browser loads a webpage, it goes through these main steps: Real-world example (ShopNest) ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

JavaScript Tutorial
Course syllabus

JavaScript Tutorial

Tutorial — Basics
Control Flow & Functions
Objects & Collections
Strings, Dates & RegEx
Async JavaScript
HTML DOM & Web APIs
Advanced
Performance & Security
Testing & Tooling
Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details