<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Understanding Variables and Data Types in JavaScript]]></title><description><![CDATA[Understanding Variables and Data Types in JavaScript]]></description><link>https://under-standing-variables-and-data-types-in-javascript.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1593680282896/kNC7E8IR4.png</url><title>Understanding Variables and Data Types in JavaScript</title><link>https://under-standing-variables-and-data-types-in-javascript.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 26 Jun 2026 12:46:45 GMT</lastBuildDate><atom:link href="https://under-standing-variables-and-data-types-in-javascript.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Variables and Data Types in JavaScript: Your First Step to Writing Real Code]]></title><description><![CDATA[Who is this for? If you are brand new to JavaScript and want to understand what variables are, how to create them, and what kinds of data they can hold — this is the perfect starting point. No prior e]]></description><link>https://under-standing-variables-and-data-types-in-javascript.hashnode.dev/variables-and-data-types-in-javascript-your-first-step-to-writing-real-code</link><guid isPermaLink="true">https://under-standing-variables-and-data-types-in-javascript.hashnode.dev/variables-and-data-types-in-javascript-your-first-step-to-writing-real-code</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><category><![CDATA[chai-code ]]></category><category><![CDATA[Data types in javascript]]></category><category><![CDATA[datatypes]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[ABHISHEK KUMAR]]></dc:creator><pubDate>Thu, 30 Apr 2026 06:01:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6784893ff404b926e9fe3b72/f96fb38d-18a4-4580-bb4d-102028cf0008.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p><strong>Who is this for?</strong> If you are brand new to JavaScript and want to understand what variables are, how to create them, and what kinds of data they can hold — this is the perfect starting point. No prior experience needed.</p>
</blockquote>
<hr />
<h2>Table of Contents</h2>
<ol>
<li><p><a href="#1-what-are-variables-and-why-do-we-need-them">What Are Variables and Why Do We Need Them?</a></p>
</li>
<li><p><a href="#2-declaring-variables-var-let-and-const">Declaring Variables: var, let, and const</a></p>
</li>
<li><p><a href="#3-primitive-data-types">Primitive Data Types</a></p>
</li>
<li><p><a href="#4-differences-between-var-let-and-const">Differences Between var, let, and const</a></p>
</li>
<li><p><a href="#5-what-is-scope">What Is Scope?</a></p>
</li>
<li><p><a href="#diagrams">Diagrams</a></p>
</li>
<li><p><a href="#practice-assignment">Practice Assignment</a></p>
</li>
</ol>
<hr />
<h2>Introduction</h2>
<p>Every program you will ever write needs to remember things — a user's name, their age, whether they are logged in, how many items are in their cart. Without a way to store and recall information, your code would be useless.</p>
<p><strong>Variables</strong> are how your program remembers things.</p>
<p>Once you understand variables and the kinds of data they can hold, you have the foundation for everything else in JavaScript. Let us build that foundation right now.</p>
<blockquote>
<p>💡 <strong>Open your browser console</strong> (<code>F12</code> → Console tab) and type along with every example. Reading code is good. Typing it is better.</p>
</blockquote>
<hr />
<h2>1. What Are Variables and Why Do We Need Them?</h2>
<h3>The box analogy</h3>
<p>Think of a variable as a <strong>labelled box</strong>. The box has a name on the outside (the variable name), and you can put a value inside it (the data). Whenever you need that value, you just look up the box by its label.</p>
<pre><code class="language-graphql">  VARIABLE NAME          VARIABLE NAME          VARIABLE NAME
       │                      │                      │
       ▼                      ▼                      ▼
 ┌───────────────┐      ┌───────────────┐      ┌───────────────┐
 │               │      │               │      │               │
 │     name      │      │      age      │      │   isStudent   │
 │               │      │               │      │               │
 ├───────────────┤      ├───────────────┤      ├───────────────┤
 │               │      │               │      │               │
 │   "Priya"     │      │      21       │      │     true      │
 │               │      │               │      │               │
 └───────────────┘      └───────────────┘      └───────────────┘
       ▲                      ▲                      ▲
       │                      │                      │
  STORED VALUE           STORED VALUE           STORED VALUE
  (a string)             (a number)             (a boolean)
</code></pre>
<p>Each box stores exactly one value. You can look at what is inside, change what is inside, or use the value to do something.</p>
<h3>Why do we need them?</h3>
<p>Without variables, you would have to repeat the same values everywhere:</p>
<pre><code class="language-javascript">// Without variables — repetitive and fragile
console.log("Hello, Priya!");
console.log("Priya has 5 unread messages.");
console.log("Welcome back, Priya.");

// If the name changes, you update it in three places — and miss one
</code></pre>
<p>With a variable, you store the value once and use it everywhere:</p>
<pre><code class="language-javascript">// With a variable — change the name in one place, everything updates
const name = "Priya";

console.log("Hello, " + name + "!");
console.log(name + " has 5 unread messages.");
console.log("Welcome back, " + name + ".");
</code></pre>
<p>Variables also let your program respond to real input — a form submission, a user clicking a button, data arriving from a server. Without variables, you cannot hold or work with any of it.</p>
<hr />
<h2>2. Declaring Variables: var, let, and const</h2>
<p>JavaScript gives you three keywords to create (declare) variables. Each one behaves slightly differently.</p>
<h3><code>let</code> — the modern standard for changeable values</h3>
<p>Use <code>let</code> when the value of a variable might change later.</p>
<pre><code class="language-javascript">let age = 20;
console.log(age); // 20

age = 21; // updating the value
console.log(age); // 21
</code></pre>
<h3><code>const</code> — for values that should never change</h3>
<p>Use <code>const</code> when the value is fixed and should not be reassigned.</p>
<pre><code class="language-javascript">const country = "India";
console.log(country); // "India"

country = "Nepal"; // ❌ TypeError: Assignment to constant variable.
</code></pre>
<p>Once you set a <code>const</code>, it is locked. Trying to change it throws an error — which is actually helpful, because it protects you from accidentally overwriting important values.</p>
<h3><code>var</code> — the old way (still works, but avoid it)</h3>
<p><code>var</code> is the original way to declare variables in JavaScript. It still works, but it has quirky behaviour that causes bugs. Modern JavaScript uses <code>let</code> and <code>const</code> instead.</p>
<pre><code class="language-javascript">var city = "Mumbai";
console.log(city); // "Mumbai"

city = "Delhi"; // var allows reassignment
console.log(city); // "Delhi"
</code></pre>
<p>You will see <code>var</code> in older code and tutorials, so it is important to recognise it — but write your own code with <code>let</code> and <code>const</code>.</p>
<h3>Declaring without a value</h3>
<p>You can declare a variable without giving it a value right away. It will hold <code>undefined</code> until you assign something.</p>
<pre><code class="language-javascript">let score;
console.log(score); // undefined

score = 95;
console.log(score); // 95
</code></pre>
<h3>Naming rules for variables</h3>
<pre><code class="language-javascript">// ✅ Valid variable names
let firstName   = "Rahul";
let age2        = 25;
let isLoggedIn  = true;
let _count      = 0;
let $price      = 499;

// ❌ Invalid variable names
let 2fast       = true;   // cannot start with a number
let my-name     = "Ria";  // hyphens not allowed
let let         = 5;      // cannot use reserved keywords
</code></pre>
<blockquote>
<p>🔑 <strong>Convention:</strong> JavaScript developers use <strong>camelCase</strong> for variable names — the first word lowercase, each following word capitalised: <code>firstName</code>, <code>totalPrice</code>, <code>isUserLoggedIn</code>.</p>
</blockquote>
<hr />
<h2>3. Primitive Data Types</h2>
<p>A <strong>data type</strong> tells JavaScript what kind of value a variable holds. The five most important types for beginners are: <code>string</code>, <code>number</code>, <code>boolean</code>, <code>null</code>, and <code>undefined</code>.</p>
<h3>String — text</h3>
<p>A string is any sequence of characters wrapped in quotes. Use single quotes <code>'...'</code>, double quotes <code>"..."</code>, or backticks <code>`...`</code>.</p>
<pre><code class="language-javascript">let name        = "Priya";
let city        = 'Mumbai';
let greeting    = `Hello, World!`;
let sentence    = "She said, 'I love JavaScript!'";

console.log(name);     // Priya
console.log greeting); // Hello, World!
</code></pre>
<p>Strings are used for names, messages, email addresses, descriptions — any text.</p>
<pre><code class="language-javascript">let email   = "priya@example.com";
let message = "Your order has been placed.";
let country = "India";
</code></pre>
<p>You can join strings together using <code>+</code>:</p>
<pre><code class="language-javascript">let firstName = "Ravi";
let lastName  = "Sharma";
let fullName  = firstName + " " + lastName;

console.log(fullName); // "Ravi Sharma"
</code></pre>
<h3>Number — numeric values</h3>
<p>Numbers in JavaScript cover both whole numbers (integers) and decimals (floats) — no distinction needed.</p>
<pre><code class="language-javascript">let age       = 22;
let price     = 499.99;
let year      = 2025;
let discount  = 0.15;
let negative  = -10;

console.log(age + 1);       // 23
console.log(price * 2);     // 999.98
console.log(year - 2000);   // 25
</code></pre>
<p>Numbers are used for ages, prices, scores, quantities, measurements — anything you calculate with.</p>
<h3>Boolean — true or false</h3>
<p>A boolean has exactly two possible values: <code>true</code> or <code>false</code>. It represents a yes/no, on/off condition.</p>
<pre><code class="language-javascript">let isLoggedIn  = true;
let isStudent   = false;
let hasDiscount = true;
let isPremium   = false;

console.log(isLoggedIn);  // true
console.log(isStudent);   // false
</code></pre>
<p>Booleans are used for conditions — is the user logged in? Has the form been submitted? Is the item in stock?</p>
<pre><code class="language-javascript">let isAboveAge  = 21 &gt;= 18;  // true
let isEven      = 7 % 2 === 0; // false
</code></pre>
<h3>null — intentionally empty</h3>
<p><code>null</code> means a variable exists but has been <strong>deliberately set to have no value</strong>. It is an intentional blank.</p>
<pre><code class="language-javascript">let selectedItem = null; // nothing selected yet

// Later, when the user selects something:
selectedItem = "Laptop";
console.log(selectedItem); // "Laptop"
</code></pre>
<p>Think of <code>null</code> as an empty box you placed on the shelf on purpose. You know the box is there — it just does not have anything in it yet.</p>
<pre><code class="language-javascript">let profilePicture = null; // user has not uploaded a photo yet
let shippingAddress = null; // address not provided yet
</code></pre>
<h3>undefined — not yet assigned</h3>
<p><code>undefined</code> means a variable has been declared but <strong>no value has been given to it at all</strong>. JavaScript sets this automatically.</p>
<pre><code class="language-javascript">let score;
console.log(score); // undefined — declared but not assigned

let username = undefined; // you can set it explicitly too, but this is rare
</code></pre>
<p>The practical difference from <code>null</code>:</p>
<pre><code class="language-plaintext">null        → you intentionally said "no value here"
undefined   → a value was never assigned (usually accidental or temporary)
</code></pre>
<h3>Checking the type of a value</h3>
<p>Use the <code>typeof</code> operator to find out what data type a variable holds:</p>
<pre><code class="language-javascript">let name      = "Priya";
let age       = 22;
let isStudent = true;
let result    = null;
let score;

console.log(typeof name);      // "string"
console.log(typeof age);       // "number"
console.log(typeof isStudent); // "boolean"
console.log(typeof result);    // "object"  ← a known quirk in JavaScript
console.log(typeof score);     // "undefined"
</code></pre>
<blockquote>
<p>⚠️ <code>typeof null</code> returns <code>"object"</code> — this is a long-standing bug in JavaScript that was never fixed to preserve backward compatibility. Just remember: <code>null</code> is not an object.</p>
</blockquote>
<h3>Data types at a glance</h3>
<table>
<thead>
<tr>
<th>Type</th>
<th>Example values</th>
<th>Used for</th>
</tr>
</thead>
<tbody><tr>
<td><code>string</code></td>
<td><code>"Priya"</code>, <code>"hello"</code>, <code>"42"</code></td>
<td>Names, text, messages</td>
</tr>
<tr>
<td><code>number</code></td>
<td><code>22</code>, <code>3.14</code>, <code>-100</code></td>
<td>Ages, prices, scores</td>
</tr>
<tr>
<td><code>boolean</code></td>
<td><code>true</code>, <code>false</code></td>
<td>Conditions, flags</td>
</tr>
<tr>
<td><code>null</code></td>
<td><code>null</code></td>
<td>Intentional empty value</td>
</tr>
<tr>
<td><code>undefined</code></td>
<td><code>undefined</code></td>
<td>Unassigned variable</td>
</tr>
</tbody></table>
<hr />
<h2>4. Differences Between var, let, and const</h2>
<h3>Reassignment</h3>
<pre><code class="language-javascript">// let — can be reassigned
let score = 80;
score = 95;
console.log(score); // 95 ✓

// const — cannot be reassigned
const maxScore = 100;
maxScore = 110; // ❌ TypeError

// var — can be reassigned (same as let in this regard)
var level = 1;
level = 2;
console.log(level); // 2 ✓
</code></pre>
<h3>Re-declaration</h3>
<pre><code class="language-javascript">// var — allows re-declaration (this is a common source of bugs)
var name = "Priya";
var name = "Rahul"; // no error — silently overwrites the first one
console.log(name); // "Rahul"

// let — does NOT allow re-declaration in the same scope
let city = "Mumbai";
let city = "Delhi"; // ❌ SyntaxError: Identifier 'city' has already been declared

// const — does NOT allow re-declaration
const country = "India";
const country = "Nepal"; // ❌ SyntaxError
</code></pre>
<p>Re-declaration with <code>var</code> is one of its biggest problems — you can accidentally create a variable with the same name as an existing one, and JavaScript will quietly overwrite it without warning.</p>
<h3>Must be initialised</h3>
<pre><code class="language-javascript">const pi = 3.14; // ✅ must give a value immediately

const gravity; // ❌ SyntaxError: Missing initializer in const declaration

let x;         // ✅ let can be declared without a value (gets undefined)
var y;         // ✅ var can be declared without a value (gets undefined)
</code></pre>
<h3>Summary comparison table</h3>
<table>
<thead>
<tr>
<th>Feature</th>
<th><code>var</code></th>
<th><code>let</code></th>
<th><code>const</code></th>
</tr>
</thead>
<tbody><tr>
<td>Can be reassigned</td>
<td>✅ Yes</td>
<td>✅ Yes</td>
<td>❌ No</td>
</tr>
<tr>
<td>Can be re-declared</td>
<td>✅ Yes</td>
<td>❌ No</td>
<td>❌ No</td>
</tr>
<tr>
<td>Must have initial value</td>
<td>❌ No</td>
<td>❌ No</td>
<td>✅ Yes</td>
</tr>
<tr>
<td>Scope</td>
<td>Function</td>
<td>Block</td>
<td>Block</td>
</tr>
<tr>
<td>Modern best practice</td>
<td>❌ Avoid</td>
<td>✅ Use</td>
<td>✅ Use</td>
</tr>
</tbody></table>
<blockquote>
<p>🔑 <strong>Simple rule for beginners:</strong> Use <code>const</code> by default. Switch to <code>let</code> only when you know the value will change. Never use <code>var</code> in new code.</p>
</blockquote>
<hr />
<h2>5. What Is Scope?</h2>
<p><strong>Scope</strong> determines where in your code a variable can be accessed. Think of it as the <strong>visibility range</strong> of a variable — from where can it be seen and used?</p>
<h3>The real-life analogy</h3>
<p>Imagine you write something on a whiteboard inside a specific room. People inside that room can read it. People outside the room cannot — even though they know the room exists.</p>
<p>Variables work the same way. A variable declared inside a block <code>{}</code> is only visible inside that block.</p>
<h3>Global scope — visible everywhere</h3>
<p>A variable declared outside any function or block is in <strong>global scope</strong>. It can be accessed from anywhere in your program.</p>
<pre><code class="language-javascript">let appName = "MyApp"; // global — accessible everywhere

function showName() {
  console.log(appName); // ✓ accessible inside a function
}

showName(); // "MyApp"
console.log(appName); // "MyApp" — also accessible outside
</code></pre>
<h3>Block scope — visible only inside { }</h3>
<p><code>let</code> and <code>const</code> are <strong>block-scoped</strong> — they only exist inside the <code>{}</code> block where they were declared.</p>
<pre><code class="language-javascript">{
  let message = "Hello from inside the block!";
  console.log(message); // ✓ accessible here
}

console.log(message); // ❌ ReferenceError: message is not defined
</code></pre>
<p>The variable <code>message</code> only lives inside the <code>{}</code>. Once you step outside the block, it is gone.</p>
<p>A practical example — inside an <code>if</code> block:</p>
<pre><code class="language-javascript">let age = 20;

if (age &gt;= 18) {
  let status = "adult"; // block-scoped to this if block
  console.log(status);  // ✓ "adult"
}

console.log(status); // ❌ ReferenceError: status is not defined
</code></pre>
<h3>Function scope — var lives inside functions</h3>
<p><code>var</code> is <strong>function-scoped</strong> — it lives inside the function it was declared in, but it is NOT limited to blocks like <code>if</code> or <code>for</code>. This is one of the reasons <code>var</code> causes bugs.</p>
<pre><code class="language-javascript">function greetUser() {
  var greeting = "Hello!";
  console.log(greeting); // ✓ "Hello!"
}

greetUser();
console.log(greeting); // ❌ ReferenceError: greeting is not defined

// BUT — var leaks out of blocks (unlike let/const):
if (true) {
  var leakyVar = "I leaked!"; // declared with var inside a block
}
console.log(leakyVar); // ✓ "I leaked!" — var ignores block boundaries!
</code></pre>
<p>The <code>leakyVar</code> example shows exactly why <code>var</code> is problematic. A variable declared inside an <code>if</code> block leaks out into the surrounding scope — that is unexpected behaviour that leads to hard-to-find bugs.</p>
<h3>Scope — simple visual summary</h3>
<pre><code class="language-plaintext">Outer scope (global)
┌──────────────────────────────────────────┐
│  let outerVar = "I am global";           │
│                                          │
│  if (true) {                             │
│  ┌────────────────────────────────────┐  │
│  │  let innerVar = "I am block only"; │  │
│  │                                    │  │
│  │  ✓ outerVar is visible here        │  │
│  │  ✓ innerVar is visible here        │  │
│  └────────────────────────────────────┘  │
│                                          │
│  ✓ outerVar is visible here              │
│  ✗ innerVar is NOT visible here          │
└──────────────────────────────────────────┘
</code></pre>
<p>Inner scopes can see outer variables. Outer scopes cannot see inner variables.</p>
<hr />
<h2>Diagrams</h2>
<h3>var, let, and const Comparison Table</h3>
<pre><code class="language-plaintext">┌─────────────────────────────────────────────────────────────┐
│          var vs let vs const — At a Glance                  │
│                                                             │
│  Feature             var        let        const            │
│  ─────────────────── ────────── ────────── ──────────       │
│  Reassign value      ✅ Yes     ✅ Yes     ❌ No             │
│  Re-declare          ✅ Yes     ❌ No      ❌ No             │
│  Initial value needed❌ No      ❌ No      ✅ Yes            │
│  Scope               Function   Block      Block             │
│  Leaks out of blocks ✅ Yes     ❌ No      ❌ No             │
│  Use in modern code  ❌ Avoid   ✅ Yes     ✅ Yes            │
│                                                             │
│  Quick decision guide:                                      │
│  ──────────────────────────────────────────────────────     │
│  Value will never change?   → const  (const PI = 3.14)      │
│  Value will change?         → let    (let score = 0)        │
│  Old/legacy code you read?  → var    (recognise it, avoid)  │
└─────────────────────────────────────────────────────────────┘
</code></pre>
<h3>Scope Visualisation</h3>
<pre><code class="language-plaintext">┌─────────────────────────────────────────────────────────────┐
│                 SCOPE VISUALISATION                         │
│                                                             │
│  GLOBAL SCOPE                                               │
│  ┌───────────────────────────────────────────────────────┐  │
│  │  const appName = "MyApp";   ← visible everywhere      │  │
│  │  let  userCount = 0;        ← visible everywhere      │  │
│  │                                                       │  │
│  │  function greet() {                                   │  │
│  │  ┌─────────────────────────────────────────────────┐  │  │
│  │  │  FUNCTION SCOPE                                 │  │  │
│  │  │  let message = "Hello!"; ← only inside greet() │  │  │
│  │  │                                                 │  │  │
│  │  │  if (true) {                                    │  │  │
│  │  │  ┌───────────────────────────────────────────┐  │  │  │
│  │  │  │  BLOCK SCOPE                              │  │  │  │
│  │  │  │  let status = "active"; ← only here       │  │  │  │
│  │  │  │  ✓ can see: status, message, appName      │  │  │  │
│  │  │  └───────────────────────────────────────────┘  │  │  │
│  │  │                                                 │  │  │
│  │  │  ✓ can see: message, appName                    │  │  │
│  │  │  ✗ cannot see: status (block scope above)       │  │  │
│  │  └─────────────────────────────────────────────────┘  │  │
│  │                                                       │  │
│  │  ✓ can see: appName, userCount                        │  │
│  │  ✗ cannot see: message, status                        │  │
│  └───────────────────────────────────────────────────────┘  │
│                                                             │
│  Rule: Inner scopes see outer. Outer cannot see inner.      │
└─────────────────────────────────────────────────────────────┘
</code></pre>
<hr />
<h2>Practice Assignment</h2>
<p>Try these exercises in your browser console or in a <code>.js</code> file.</p>
<hr />
<h3>Task 1 — Declare your variables</h3>
<p>Declare variables for your name, age, and student status. Then print them all.</p>
<pre><code class="language-javascript">const name      = "Priya";   // your name will not change
let   age       = 21;        // age can change (birthday!)
let   isStudent = true;      // might change after graduation

console.log("Name:",      name);
console.log("Age:",       age);
console.log("Is student:", isStudent);

// Output:
// Name: Priya
// Age: 21
// Is student: true
</code></pre>
<hr />
<h3>Task 2 — Update a <code>let</code> variable</h3>
<p>Change the value of <code>age</code> and <code>isStudent</code> to see that <code>let</code> allows updates.</p>
<pre><code class="language-javascript">let age       = 21;
let isStudent = true;

console.log("Before:", age, isStudent); // 21 true

age       = 22;
isStudent = false;

console.log("After:", age, isStudent);  // 22 false
</code></pre>
<hr />
<h3>Task 3 — Try reassigning a <code>const</code></h3>
<p>Observe what happens when you try to change a <code>const</code>.</p>
<pre><code class="language-javascript">const name = "Priya";
console.log(name); // "Priya"

name = "Rahul"; // ← type this and run it

// Expected output:
// TypeError: Assignment to constant variable.
</code></pre>
<p>This error is JavaScript protecting you. Once a value is declared with <code>const</code>, it cannot be changed — intentionally.</p>
<hr />
<h3>Task 4 — Explore data types with typeof</h3>
<p>Declare one variable of each type and check them with <code>typeof</code>.</p>
<pre><code class="language-javascript">const userName   = "Ananya";
const userAge    = 19;
const isPremium  = false;
const wishlist   = null;
let   lastLogin; // not yet assigned

console.log(typeof userName);   // "string"
console.log(typeof userAge);    // "number"
console.log(typeof isPremium);  // "boolean"
console.log(typeof wishlist);   // "object"  ← the null quirk
console.log(typeof lastLogin);  // "undefined"
</code></pre>
<hr />
<h3>Bonus — Put it all together</h3>
<p>Build a small profile card using all five data types:</p>
<pre><code class="language-javascript">const fullName      = "Ravi Sharma";       // string
const age           = 24;                  // number
const isVerified    = true;                // boolean
const profilePic    = null;               // null — not uploaded yet
let   lastActiveAt;                        // undefined — not yet known

console.log("=== User Profile ===");
console.log("Name:",       fullName);
console.log("Age:",        age);
console.log("Verified:",   isVerified);
console.log("Photo:",      profilePic);
console.log("Last active:", lastActiveAt);

// Output:
// === User Profile ===
// Name:       Ravi Sharma
// Age:        24
// Verified:   true
// Photo:      null
// Last active: undefined
</code></pre>
<hr />
<h2>Quick Reference</h2>
<pre><code class="language-javascript">// ─── Variable declaration ─────────────────────────────────
const name    = "Priya";   // fixed — cannot change
let   score   = 0;         // flexible — can change
var   old     = "avoid";   // legacy — avoid in new code

// ─── Updating values ──────────────────────────────────────
score = 95;             // ✅ let allows this
name  = "Rahul";        // ❌ const does not allow this

// ─── Five primitive data types ────────────────────────────
const str  = "Hello";   // string
const num  = 42;        // number
const bool = true;      // boolean
const empty = null;     // null
let   unset;            // undefined

// ─── Check data type ──────────────────────────────────────
typeof "Hello"           // "string"
typeof 42                // "number"
typeof true              // "boolean"
typeof null              // "object" ← quirk, not a real object
typeof undefined         // "undefined"

// ─── String joining ───────────────────────────────────────
const greeting = "Hello, " + name + "!"; // "Hello, Priya!"
</code></pre>
<hr />
<h2>Wrapping Up</h2>
<p>You have just learned one of the most foundational concepts in all of programming. Here is a summary of everything covered:</p>
<ul>
<li><p>A <strong>variable</strong> is a named container that stores a value — like a labelled box</p>
</li>
<li><p>Use <code>const</code> for values that never change, <code>let</code> for values that do, and recognise <code>var</code> in old code but avoid writing it yourself</p>
</li>
<li><p>JavaScript has five <strong>primitive data types</strong>: <code>string</code> (text), <code>number</code> (numeric), <code>boolean</code> (true/false), <code>null</code> (intentionally empty), and <code>undefined</code> (not yet assigned)</p>
</li>
<li><p><strong>Scope</strong> determines where a variable is visible — <code>let</code> and <code>const</code> are block-scoped, meaning they only exist inside the <code>{}</code> where they were declared</p>
</li>
<li><p>Inner scopes can see outer variables — outer scopes cannot see inner ones</p>
</li>
</ul>
<p>Every JavaScript concept you learn from here — functions, loops, conditionals, objects, APIs — will use variables. The clearer your understanding of this foundation, the faster everything else will click.</p>
<p>Happy coding! 🚀</p>
<hr />
<p><em>Open your console right now and type these examples yourself. Even five minutes of hands-on practice beats an hour of reading.</em></p>
]]></content:encoded></item></channel></rss>