<?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[These are the building blocks of almost every program you will write.]]></description><link>https://understanding-variables-datatypes-javascript-by-koushik.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/69371c590b8af498352a6399/a3c0a1e2-3f5d-4156-91b2-bf2c3dea1a34.jpg</url><title>Understanding Variables and Data Types in JavaScript</title><link>https://understanding-variables-datatypes-javascript-by-koushik.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 05:20:27 GMT</lastBuildDate><atom:link href="https://understanding-variables-datatypes-javascript-by-koushik.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding Variables and Data Types in JavaScript]]></title><description><![CDATA[In this article, you will learn how to create and use variables and also learn about the different data types in JavaScript and how to use them.

A) Variables
In JavaScript, a variable is like a label]]></description><link>https://understanding-variables-datatypes-javascript-by-koushik.hashnode.dev/understanding-variables-and-data-types-in-javascript</link><guid isPermaLink="true">https://understanding-variables-datatypes-javascript-by-koushik.hashnode.dev/understanding-variables-and-data-types-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Blogs]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[variables]]></category><category><![CDATA[datatypes]]></category><dc:creator><![CDATA[Koushik Karmakar]]></dc:creator><pubDate>Mon, 09 Mar 2026 17:36:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/69371c590b8af498352a6399/b6454bb7-c138-4003-b6ca-47abba36b30d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, you will learn how to create and use variables and also learn about the different data types in JavaScript and how to use them.</p>
<hr />
<h2><strong>A) Variables</strong></h2>
<p>In JavaScript, a <strong>variable</strong> is like a labeled box or container that holds a value for later use. Think of a container of grapes with a label “grapes”: the label (variable name) points to the grapes (the value) inside. Formally, a variable is a named reference to a value stored in memory. For example, you might declare a variable <code>let name = "Koushik";</code> so that you can use <code>name</code> in your code instead of just typing the string <code>"Koushik"</code>.</p>
<h2>B) <strong>How to Declare a Variable</strong></h2>
<p>You declare variables in JS using one of three keywords: <code>var</code>, <code>let</code>, or <code>const</code>. For example:</p>
<pre><code class="language-typescript">var name = "Alice";
let age = 25;
const isStudent = true;
console.log(name, age, isStudent); //return Alice 25 true
</code></pre>
<p><code>var name = "Alice";</code> uses the old-style <code>var</code> keyword. Historically this was the only way to declare variables.</p>
<p><code>let age = 25;</code> (ES6+) declares a block-scoped, reassignable variable. For example:</p>
<pre><code class="language-js">let count = 0;
console.log(count); // 0
count = 1;          // reassigning is allowed
console.log(count); // 1
</code></pre>
<p><code>const isStudent = true;</code> (ES6+) declares a block-scoped <em>constant</em>. It must be initialized immediately and cannot be reassigned. For example:</p>
<pre><code class="language-typescript">const isStudent = true;
console.log(isStudent);   // true
isStudent = false;      // Error: Assignment to constant variable
</code></pre>
<blockquote>
<p>Variables declared with <code>var</code> or <code>let</code> can be reassigned to new values as shown, but <code>const</code> variables cannot be changed after their first assignment.</p>
</blockquote>
<h2><strong>C) Variable Assignment and Initialization</strong></h2>
<p>We can assign a value to a variable by using the assignment (<code>=</code>) operator—the variable name to the left of it, and the value to the right.</p>
<pre><code class="language-typescript">score = 1;
</code></pre>
<p>The code snipped above assigns <code>1</code> as the value of <code>score</code> , this is called <strong>variable assignment</strong>.</p>
<p>When we combine variable declaration and assignment in one operation, it is called <strong>variable initialization</strong>.</p>
<pre><code class="language-javascript">let score = 1;
</code></pre>
<p>As seen above, we declare the variable <code>score</code>, and immediately on the same line, assign the value <code>1</code> to it.</p>
<h2>D) <strong>Key Differences:</strong> <code>var</code> <strong>vs</strong> <code>let</code> <strong>vs</strong> <code>const</code></h2>
<p>The three keywords mainly differ in <strong>scope</strong> and <strong>mutability</strong>:</p>
<ol>
<li><p><code>var</code><strong>:</strong> Function-scoped (or global if outside any function). The declaration is hoisted (initialized to <code>undefined</code> if accessed before the <code>var</code> line). You <em>can</em> redeclare and reassign a <code>var</code> variable in the same scope. It's a old method to declare a variable.</p>
</li>
<li><p><code>let</code><strong>:</strong> Block-scoped, also hoisted, but it cannot be used before its declaration (it lives in a “temporal dead zone called TLD”). You cannot redeclare the same <code>let</code> name in one scope, but you <em>can</em> reassign it. When you reassign it then it will change the value of that variable.</p>
</li>
<li><p><code>const</code><strong>:</strong> Block-scoped like <code>let</code>, with the additional rule that it must be initialized when declared and cannot be reassigned. It also cannot be redeclared in the same scope. So you can not change its value in the same scope.</p>
</li>
</ol>
<h2>E) <strong>Reserved Words in JavaScript</strong></h2>
<p>We can create variables as we wish, some names are already being used within JavaScript to mean something specific. They are reserved words in JavaScript. Below are all the reserved words in JavaScript:</p>
<p><code>arguments</code> <code>await</code> <code>break</code> <code>case</code> <code>catch</code> <code>class</code> <code>const</code> <code>continue</code> <code>debugger</code> <code>default</code> <code>delete</code> <code>do</code> <code>else</code> <code>enum</code> <code>eval</code> <code>export</code> <code>extends</code> <code>false</code> <code>finally</code> <code>for</code> <code>function</code> <code>if</code> <code>implements</code> <code>import</code> <code>in</code> <code>Infinity</code> <code>instanceof</code> <code>interface</code> <code>let</code> <code>NaN</code> <code>new</code> <code>null</code> <code>package</code> <code>private</code> <code>protected</code> <code>public</code> <code>return</code> <code>static</code> <code>super</code> <code>switch</code> <code>this</code> <code>throw</code> <code>true</code> <code>try</code> <code>typeof</code> <code>undefined</code> <code>var</code> <code>void</code> <code>while</code> <code>with</code> <code>yield</code></p>
<blockquote>
<p>You do not need to memorize these keywords. If you try to use them, you'll get an error and you'll learn to recognize and know them with experience.</p>
</blockquote>
<img src="https://cdn.hashnode.com/uploads/covers/69371c590b8af498352a6399/0df5e97d-c587-48bd-bb77-37d0eea6a8df.jpg" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>F) Variable Data Types</strong></h2>
<p>Data type simply means "type of data". In JavaScript, we store values of different types in variables. Data types in JavaScript are categorized into two primary groups, namely;</p>
<p><strong>1) Primitive</strong>: Number, String, Boolean, Undefined, Null, BigInt, Symbol<br />2) <strong>Reference</strong>: Object, Array, Function</p>
<img src="https://cdn.hashnode.com/uploads/covers/69371c590b8af498352a6399/8c969314-d59d-43a4-a911-0a07c610a481.webp" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>G) Primitive Data Types</strong></h2>
<p>JavaScript has several <em>primitive</em> (simple) data types. The most common ones are <strong>number</strong>, <strong>string</strong>, <strong>boolean</strong>, <strong>null</strong>, and <strong>undefined</strong>. Each holds a single value:</p>
<p><strong>1) Number:</strong> numeric values, e.g. <code>let age = 30;</code>.<br />2) <strong>String:</strong> text enclosed in quotes, e.g. <code>let name = "Alice";</code>.<br />3) <strong>Boolean:</strong> true/false values, e.g. <code>let isStudent = true;</code>.<br />4) <strong>Undefined:</strong> means “no value yet.” If you declare <code>let x;</code> without assigning it, its value is <code>undefined</code>. For example:</p>
<pre><code class="language-js">let x;
console.log(x); // undefined
</code></pre>
<p><strong>5) Null:</strong> explicitly means “no value.” It’s a value you can assign to indicate emptiness. For example:</p>
<pre><code class="language-js">let y = null;
console.log(y); // null
</code></pre>
<p>Each of these primitives holds a simple value directly (without extra structure). In fact, for primitive variables, the value is stored directly in the variable’s memory slot:</p>
<hr />
<h2>H) Non <strong>Primitive /</strong> <strong>Reference Types in JavaScript</strong></h2>
<p>We talked about <strong>primitive data types</strong>, which store simple values like numbers or text. But in real applications we often need to store <strong>multiple values or complex data</strong>. For that, JavaScript provides <strong>non-primitive data types</strong>. Non-primitive types are also called <strong>reference types</strong>.</p>
<p>These include:<br /><strong>1)</strong> <strong>Object</strong><br /><strong>2) Array</strong><br /><strong>3) Function</strong></p>
<p>These types can <strong>store collections of data or more complex structures</strong>.</p>
<hr />
<h2>1) Object</h2>
<p>An <strong>object</strong> is a collection of related data stored as <strong>key–value pairs</strong>. Think of an object like a <strong>student profile card</strong>.</p>
<p>Example:</p>
<pre><code class="language-typescript">const student = {
  name: "Koushik",
  age: 21,
  isStudent: true
};

console.log(student.name);  //Koushik
</code></pre>
<p>Explanation:</p>
<ul>
<li><p><code>name</code>, <code>age</code>, and <code>isStudent</code> are <strong>keys</strong></p>
</li>
<li><p><code>"Koushik"</code>, <code>21</code>, <code>true</code> are <strong>values</strong></p>
</li>
</ul>
<p>Objects help organize related data in one place.</p>
<p>Real-world example:</p>
<pre><code class="language-typescript">const car = {
  brand: "Toyota",
  model: "Fortuner",
  year: 2023
};
</code></pre>
<hr />
<h2>2) Array</h2>
<p>An <strong>array</strong> is used to store <strong>multiple values in a single variable</strong>.</p>
<p>Example:</p>
<pre><code class="language-typescript">const fruits = ["Apple", "Mango", "Banana"];

console.log(fruits[0]);  //Apple
</code></pre>
<p>Explanation:</p>
<ul>
<li><p>Arrays store values in <strong>order</strong></p>
</li>
<li><p>Each value has an <strong>index</strong></p>
</li>
<li><p>Index starts from <strong>0</strong></p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-typescript">Index →   0        1        2
Value → "Apple" "Mango" "Banana"
</code></pre>
<p>Arrays are useful when you need to store <strong>lists of data</strong>.</p>
<p>Example:</p>
<pre><code class="language-typescript">const marks = [85, 90, 78, 92];
</code></pre>
<hr />
<h2>3. Function</h2>
<p>A <strong>function</strong> is a reusable block of code that performs a specific task.</p>
<p>Example:</p>
<pre><code class="language-typescript">function greet() {
  console.log("Hello World");
}

greet();  //Hello World
</code></pre>
<p>Functions help avoid repeating the same code.</p>
<p>Example:</p>
<pre><code class="language-typescript">function add(a, b) {
  return a + b;
}

console.log(add(5, 3));   //8
</code></pre>
<hr />
<h2><strong>Summary</strong></h2>
<p>Variables are "pointers" to values. When you mention (use) a variable anywhere in your code, the variable identifier (name) is replaced with the value it points to. It's just like calling someone's name. The name doesn't respond, the person (value) behind the name is what you hope to get as a response. This article also showed you the different data types in JavaScript and how to use them.</p>
]]></content:encoded></item></channel></rss>