Welcome, welcome: Hello, I am back again with the new article of our "JavaScript" series as promised! In part 1 and part 2, we gained knowledge about what programming really is, why we are learning JavaScript as our first language, and how we can run...

Hello, I am back again with the new article of our "JavaScript" series as promised! In part 1 and part 2, we gained knowledge about what programming really is, why we are learning JavaScript as our first language, and how we can run JavaScript in our system in different ways.
Here in part 3 of this JavaScript series, we are going to taste some real essence of JavaScript. There are different things like variables, data types, different operations, and many more. Wait… wait… wait… don't get tensed after reading so many jargons! We will understand everything in a very simple manner, so do not take stress, just enjoy, focus, and relax…
Before diving in, let's add a little fun! Run this in your console:
let name = prompt("Enter your name:");
console.log(`Hello, ${name}! Welcome to JavaScript.`);
Try it out and see how JavaScript interacts with user input! Now, let’s get started with variables. 🎩✨
Think about your school days, maybe 7th or 8th grade. We were introduced to algebra, where we first saw an unknown number called "x"—then came "y"—and soon, the whole English alphabet was used as variables!
A variable is like a placeholder where values can change anytime. Think about calculating the result of 2x + 3x + 5, where x = 5. If we change x to 7, the whole result changes!
In programming, a variable is just a container (like a jar where we store different grocery items) that holds data efficiently.
In JavaScript, we have three ways to declare variables:
let
const
var (which we will avoid using!)
Let's create our first variable:
let x;
// We've created a variable 'x' but haven't assigned any value yet.
x = 10;
// Now, we assign the value 10 to 'x'.
console.log(x); // Output: 10
📝 Quick Check: 1️⃣ Create a variable year, assign the current year, and print it to the console. 2️⃣ Create a variable name, assign your name, and print it to the console.
Let’s see how we can change the value of a variable.
let game = "cricket";
console.log(game); // Output: cricket
game = "football";
console.log(game); // Output: football
📝 Quick Check: Create a variable age, assign a value, print it, then change the value and print it again.
let vs. const: The Big Difference!🚀 Key takeaway:
let allows you to change the value later.
const locks the value, meaning you cannot reassign it.
const number1 = 20;
console.log(number1); // Output: 20
number1 = 40; // ❌ ERROR: Assignment to constant variable!
So, always remember: Use const when you don't want the value to change. In the upcoming articles of this series , we will see the specific use cases of const in detail.
var (For Your Own Good!)JavaScript has evolved, and using var can introduce unnecessary bugs and complexity. So, as per modern JavaScript standards, we will avoid using var.
🚀 Homework: 1️⃣ Try creating different variables using let and const. 2️⃣ What happens when you try to reassign a const variable? 3️⃣ Can you think of a real-world example where using const makes more sense than let?
Now that we know how to create variables, let’s talk about what kind of data we can store in them. JavaScript has different types of data, just like we have different kinds of items in a grocery store!
Here are the main types of data in JavaScript:
1️⃣ Numbers: Whole numbers or decimals (e.g., 5, 10.5).
2️⃣ Strings: Text enclosed in quotes (e.g., "Hello", 'JavaScript').
3️⃣ Booleans: true or false (like an ON/OFF switch).
4️⃣ Undefined: When a variable is declared but has no value.
5️⃣ Null: Represents an intentional empty value.
6️⃣ Objects: Collections of data (we’ll learn this later!).
7️⃣ Arrays: Lists of values (more on this later too!).
Let's see some examples:
let number = 25; // Number
typeof number; // Output: "number"
let text = "JavaScript is fun!"; // String : String value alwaus enclosed with quotes
typeof text; // Output: "string"
let isCodingFun = true; // Boolean
typeof isCodingFun; // Output: "boolean"
let unknown; // Undefined
typeof unknown; // Output: "undefined"
let empty = null; // Null
typeof empty; // Output: "object" (weird, but that's JavaScript!)
📝 Quick Check: 1️⃣ Create a variable for each data type and print the value in the console. 2️⃣ Use typeof to check the type of each variable.
| Data Type | Example | Description |
| --- | --- | --- |
| Number | let num = 25; | Represents numerical values, including decimals. |
| String | let name = "Alice"; | Text enclosed in quotes. |
| Boolean | let isHappy = true; | Can be true or false. |
| Undefined | let x; | A variable declared but not assigned a value. |
| Null | let empty = null; | Represents an intentional absence of a value. |
| Object | let person = {name: "Bob", age: 30}; | Stores multiple values in a structured format. |
| Array | let colors = ["red", "blue", "green"]; | A list of values. |
In programming, operators are like the tools we use to manipulate data and perform different actions. Just like in real life, where we use tools like a calculator to add, subtract, multiply, or compare numbers, JavaScript operators help us process and control data efficiently.
For example, if you want to build a game where a player's score increases when they collect a coin, you'll need an arithmetic operator (+). If you want to check if the player has enough points to level up, you'll need a comparison operator (>=). And if you want to apply conditions (like checking if the player has a key or a password to unlock a door), logical operators (||, &&) help!
Now, let's explore these operators in action.
Used for mathematical operations:
let a = 10;
let b = 5;
console.log(a + b); // Addition -> 15
console.log(a - b); // Subtraction -> 5
console.log(a * b); // Multiplication -> 50
console.log(a / b); // Division -> 2
console.log(a % b); // Modulus (remainder) -> 0
Used to compare values:
console.log(10 > 5); // true
console.log(10 < 5); // false
console.log(10 == "10"); // true (loose comparison)
console.log(10 === "10"); // false (strict comparison)
Used for logical conditions:
console.log(true && false); // false (AND)
console.log(true || false); // true (OR)
console.log(!true); // false (NOT)
📝 Quick Check: 1️⃣ Try different arithmetic operations. 2️⃣ Experiment with comparison and logical operators.
This is just the beginning! Stay tuned for the next part, where we will explore functions, conditionals, and loops and also more depth discussion on data types. Until then, experiment, play around, and don’t hesitate to try your own magic with JavaScript! ✨🔥
Create a variable favoriteColor and assign your favorite color as a string. Print it.
Create a variable birthYear and assign the year you were born. Print it.
Declare a variable pet = "cat" and print it.
Change its value to "dog" and print it again.
let vs const PracticeCreate a const variable earth = "Our Planet". Try changing its value. What happens?
Create a let variable age, assign your age, and then increase it by 1. Print the updated value.
typeof)Create variables for your name, age, height (decimal), and isStudent (true/false).
Use console.log(typeof variableName) to check each data type.
Create two numbers, a = 10 and b = 5.
Print the result of a + b, a - b, a * b, a / b, and a % b.
Check if 10 > 5, 10 < 5, and 10 == "10".
What happens when you try 10 === "10"?
prompt()Ask the user for their name using prompt() and print a greeting:
let userName = prompt("Enter your name:");
console.log("Hello, " + userName + "! Welcome to JavaScript.");
Run the code in the browser and observe how it works!
💬 Share your answers and thoughts in the comments. Let's learn together! 🚀
If you are facing any trouble to understand any of these concept after trying with google search, feel free to contact me through email, X, or LinkedIn.
Subscribe to get notified when I publish new insights on JavaScript, web development, and software engineering.
No spam. Unsubscribe anytime.