JavaScript Basics – Variables and Data Types (JS-01)

Track: JavaScript Basics
Lesson: JS-01 / JS-10

🎯 Lesson Goal

By the end of this lesson, you will understand how to store data in JavaScript using variables and identify different data types used in real-world programming.


📌 Prerequisites

  • Basic computer knowledge
  • No prior programming experience required

📘 What is JavaScript?

JavaScript is a programming language used to make web pages interactive.
It allows us to:

  • Respond to user actions
  • Change content dynamically
  • Build web and server-side applications

📘 What are Variables?

A variable is a container used to store data in memory.

Think of it as a labeled box where you keep information for later use.

Example:

let name = "Kavita";
let age = 25;

Here:

  • name stores text
  • age stores a number

🧩 Declaring Variables in JavaScript

JavaScript provides three keywords to declare variables:

1️⃣ var (old way – avoid)

var city = "Delhi";

Problems with var:

  • Function-scoped
  • Can cause bugs
  • Not recommended in modern JS

2️⃣ let (recommended)

let course = "JavaScript";
course = "MERN Stack";
  • Block-scoped
  • Value can be changed

3️⃣ const (constant value)

const institute = "Programming Empire";
  • Block-scoped
  • Value cannot be changed

📘 JavaScript Data Types

Data types specify what kind of data a variable can store.


🔢 1. Number

Stores numeric values (integers and decimals).

let marks = 85;
let price = 199.99;

🔤 2. String

Stores text data (written inside quotes).

let studentName = "Aman";
let city = 'Delhi';

✔️ 3. Boolean

Stores true or false.

let isLoggedIn = true;
let hasPaid = false;

❓ 4. Undefined

A variable declared but not assigned a value.

let result;
console.log(result); // undefined

🚫 5. Null

Represents no value intentionally.

let response = null;

📦 6. Object

Stores multiple values in a single variable.

let student = {
  name: "Riya",
  age: 22,
  course: "BCA"
};

📋 7. Array

Stores multiple values in an ordered list.

let subjects = ["HTML", "CSS", "JavaScript"];

🔍 Using typeof Operator

To check the data type of a variable:

typeof 10;          // number
typeof "Hello";     // string
typeof true;        // boolean
typeof {};          // object

⚠️ Common Mistakes

  • Using var instead of let or const
  • Forgetting quotes for strings
  • Trying to change a const value
  • Confusing null with undefined

🧠 Practice Tasks

  1. Declare a variable for your name using let
  2. Declare a constant for your institute name
  3. Create an array of 5 programming languages
  4. Create an object storing student details
  5. Use typeof to check each variable

📝 Summary

  • Variables store data in memory
  • let and const are preferred over var
  • JavaScript supports multiple data types
  • Objects and arrays store complex data
  • typeof helps identify data types

➡️ Next Lesson

JavaScript Operators and Expressions (JS-02)


🏅 Quiz & Badge

Quiz and badges will be enabled soon.

6 thoughts on “JavaScript Basics – Variables and Data Types (JS-01)”

    • Author gravatar

      Thanks foor your personal marvcelous posting! I really enjoyed reading it,
      youu may be a great author. I will be sure to bookmark your blog annd will eventujally
      coime bac later in life. I want to encourage continue your grreat posts, have
      a nice afternoon! xnxx

    • Author gravatar

      Greeat items from you, man. I’ve be mindful your stuff prioor to and you are just extremely great.
      I actually like what you hav boufht here, certainly like what yyou aree statig and the
      waay iin which wherein you asert it. Youu are makingg it enjoyable annd yyou still care ffor
      tto keep it wise. I cann not wait to learn far moe from you.Thiss iis actually a
      tremendous wweb site. xnxx

    • Author gravatar

      Tanks forr finally talking about > JavaScript Basics – Variables and Data Typss (JS-01) – Progrfammingempire < Loved it! xnxx

    • Author gravatar

      Grwat goods from you, man. I’ve understand your stuff previouss
      to and you’re just too magnificent. I actually like what you’ve acqured here,
      certainly lik what you’re saying and thhe way inn which you say it.
      You make it enjoyable andd you still cawre forr to keep it smart.
      I can’t wait too read much more from you. This iss actually a terrific website.

      xnxx

    • Author gravatar

      Thanks for sgaring youur thoughts about . Regard xnxx

Leave a Reply

Your email address will not be published. Required fields are marked *