Skip to main content

Command Palette

Search for a command to run...

Day 1: JavaScript Variables and Data Types Explained Simply

Learn how JavaScript stores and handles data, The foundation of every web app.

Updated
3 min read
Day 1: JavaScript Variables and Data Types Explained Simply
A

Here’s a clean non-bullet, blog-friendly “About Me” for your Hashnode page: I’m a Frontend Developer based in Pune with experience in Angular, TypeScript, JavaScript, HTML, and CSS. I enjoy building clean, scalable interfaces and working on products like dashboards, ERP systems, and B2B platforms. My focus is on writing maintainable code, improving performance, and creating user-friendly experiences. I also explore concepts around UI architecture, component patterns, and frontend best practices, which I document and share through my blogs. My goal is to create helpful, practical content for developers who are learning and building real-world projects.

What is JavaScript?

JavaScript (JS) is a computer language that makes web pages interactive.
It helps you add things like buttons that work, forms that respond, and animations that move.
While HTML builds the structure and CSS makes it look good, JavaScript makes it come alive.

Example

 <button> Click me! </button> <!-- Without JavaScript -->
<button onclick="alert('Hello, World!')"> Click me!</button> <!-- With JavaScript -->

JavaScript is what turns a static webpage into an interactive experience from buttons and popups to real-time apps and games.

Variable

A variable is like a container that holds data.
You can store, use, and change values inside it anytime.

Variables in JavaScript are like water bottles they hold something, but not all bottles behave the same.

Var : The Leaky Bottle

You can pour out the water, fill it again, and even spill it everywhere.
It doesn’t care where it leaks, that’s why it’s not safe to use anymore.

var is the old way to declare variables in JavaScript.
You can change its value and even re-declare it.
It does not follow block rules, so it can leak outside { }.

Example :

var bottle = "Water";
bottle = "Juice";
console.log(bottle); // Juice

var city = "Pune";
var city = "Delhi"; // ✅ works
console.log(city); // Delhi

let : The Refillable Bottle

You can change what’s inside, but it stays sealed inside one place (your block).
If you put it somewhere else, it won’t spill over.

let is the modern way to declare variables.
You can change its value, but cannot re-declare it in the same block.
It follows block scope, meaning it stays inside { }.

Example :

let drink = "Coffee";
drink = "Tea";
console.log(drink); // Tea

let age = 25;
age = 26; // ✅ works
let age = 30; // ❌ Error

const : The Sealed Bottle

Once sealed, you can’t change what’s inside.
It’s frozen — permanent — like bottled soda you can’t refill.

const is used when you don’t want the value to change.
You must assign a value when declaring it, and it can’t be changed or re-declared.

Example :

const soda = "Coke";
soda = "Pepsi"; // ❌ Error

const country = "India";
country = "USA"; // ❌ Error

In short:

  • Use let for changing values

  • Use const for fixed values

  • Avoid var in modern JavaScript

var leaks, let keeps, const locks.

Data Types in JavaScript

A data type means what kind of value a variable holds.
Think of it like “what’s inside your box.

Data-TypeDescriptionExample
StringAnything inside " " or ' ' is a string.let name = "Adiba";
NumberAll numberslet age = 25; let price = 99.99;
Booleantrue or falselet isOnline = true; let isAdmin = false;
Arraylist of valueslet skills = ["HTML", "CSS", "JavaScript"];
Objectdata with labelslet user = { name: "Adiba", city: "Pune", age: 25 };
Undefineddeclared but not given a valuelet country;
Nullempty on purposelet car = null;

🧠 Task

1) Write a short script that prints:

  • One leaky bottle (var)

  • One refillable bottle (let)

  • One sealed bottle (const)

Then change their values and observe what happens in the console.

2) Make one variable for each data type and print all of them in one console statement.
Example:

console.log(name, age, isOnline, skills, user, country, car);

🚀 Coming Up Next

Tomorrow → Day 2: Functions and Arrow Functions
We’ll teach JavaScript to think and repeat actions with reusable code.

Master JavaScript in 7 Days Like a Pro

Part 1 of 4

A structured 7-day journey that covers JavaScript fundamentals through simple explanations and practical examples. Each day focuses on one core concept with hands-on exercises suitable for real frontend projects.

Up next

DAY 4 : Objects & Nested Objects

Objects are the backbone of JavaScript and TypeScript.Every real-world app Angular apps, APIs, e-commerce systems, dashboards — use objects everywhere. Think of an object like a box that stores information with labels. ⭐ What Is an Object? An object...

More from this blog

M

Master JavaScript in 7 Days

7 posts

Make beginners comfortable with JavaScript fundamentals through examples, visuals, and coding tasks one topic per day.