<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brian Kipchirchir</title>
    <description>The latest articles on DEV Community by Brian Kipchirchir (@briankipchirchir77).</description>
    <link>https://dev.to/briankipchirchir77</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4016306%2F07304ced-8b58-4a1e-b9b8-d708604e1118.jpg</url>
      <title>DEV Community: Brian Kipchirchir</title>
      <link>https://dev.to/briankipchirchir77</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/briankipchirchir77"/>
    <language>en</language>
    <item>
      <title>Day 1: Variables, Data Types &amp; Operators</title>
      <dc:creator>Brian Kipchirchir</dc:creator>
      <pubDate>Fri, 07 Aug 2026 20:11:50 +0000</pubDate>
      <link>https://dev.to/briankipchirchir77/day-1-variables-data-types-operators-emo</link>
      <guid>https://dev.to/briankipchirchir77/day-1-variables-data-types-operators-emo</guid>
      <description>&lt;p&gt;📦 What is a variable?&lt;/p&gt;

&lt;p&gt;A labeled box that stores a value so you can use it later.&lt;/p&gt;

&lt;p&gt;JavaScript gives you three ways to create one: var, let, and const.&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
var oldWay = "I still work but I'm outdated";&lt;/p&gt;

&lt;p&gt;let score = 10;&lt;br&gt;
score = 20; // ✅ totally fine, let allows you to reassign.&lt;/p&gt;

&lt;p&gt;const birthYear = 2003;&lt;br&gt;
// birthYear = 2004; // 🚫 throws an error, const doesn't allow reassignment&lt;/p&gt;

&lt;p&gt;🕰️ var — old-school, function-scoped,it leaks out of blocks like if statements and loops.Var usually causes weird bugs. Don't use it in new code.&lt;/p&gt;

&lt;p&gt;✅ let — modern, block-scoped, use when the value will change.&lt;/p&gt;

&lt;p&gt;🔒 const — modern, block-scoped, use by default unless you know the value needs to change.&lt;/p&gt;

&lt;p&gt;🧠 Scope: where a variable is allowed to "live".&lt;/p&gt;

&lt;p&gt;let and const being block-scoped means → they only exist inside the { } they were created in.&lt;br&gt;
js&lt;br&gt;
if (true) {&lt;br&gt;
  var leaky = "I escape the block!";&lt;br&gt;
  const trapped = "I stay inside the block";&lt;br&gt;
  let alsoTrapped = "Me too, I stay inside the block";&lt;/p&gt;

&lt;p&gt;// ✅ all three work fine HERE, still inside the block&lt;br&gt;
  console.log(leaky);       // "I escape the block!"&lt;/p&gt;

&lt;p&gt;console.log(trapped);     // "I stay inside the block"&lt;/p&gt;

&lt;p&gt;console.log(alsoTrapped); // "Me too, I stay inside the block"&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// Outside the block now:&lt;br&gt;
console.log(leaky);       // ✅ "I escape the block!" — var doesn't respect the block&lt;/p&gt;

&lt;p&gt;console.log(trapped);     // ❌ ReferenceError — const is block-scoped&lt;/p&gt;

&lt;p&gt;console.log(alsoTrapped); // ❌ ReferenceError — let is block-scoped too&lt;/p&gt;

&lt;p&gt;🔑 Takeaway: let and const behave identically on scope — both are trapped inside their block. They only differ on reassignment (next section).&lt;/p&gt;

&lt;p&gt;🍾 The const bottle analogy — identity vs. contents&lt;/p&gt;

&lt;p&gt;const locks the name's connection to a specific bottle — not what's poured inside that bottle.&lt;/p&gt;

&lt;p&gt;Picture three layers:&lt;/p&gt;

&lt;p&gt;The name (aqua) — the label&lt;br&gt;
The bottle — the actual container in memory&lt;br&gt;
The contents — whatever liquid is inside right now&lt;br&gt;
js&lt;br&gt;
const aqua = { content: "water" };&lt;/p&gt;

&lt;p&gt;This line only runs once — it creates a bottle, fills it with water, and permanently glues the name aqua to that one bottle. It's a snapshot of the starting contents, not a permanent rule about what the bottle must always hold.&lt;/p&gt;

&lt;p&gt;You CAN refill the same bottle — editing contents is always allowed, even with const:&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
aqua.content = "wine";&lt;br&gt;
console.log(aqua); // { content: "wine" } — same bottle, just refilled&lt;/p&gt;

&lt;p&gt;Same bottle, same name, only the liquid inside changed. aqua never stopped pointing at that exact bottle.&lt;/p&gt;

&lt;p&gt;You CANNOT swap in a whole new bottle — that's reassignment, and const blocks it:&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
aqua = { content: "juice" }; // ❌ error — this is a brand NEW bottle, not a refill&lt;/p&gt;

&lt;p&gt;This fails because you're not pouring juice into the existing bottle — you're trying to make the name aqua point to a completely different container. const only ever locked the name-to-bottle connection, and this line tries to break that connection.&lt;/p&gt;

&lt;p&gt;🔑 One-line summary: const = "this name will always point to this exact bottle" — not "this bottle can never change what's inside it."&lt;/p&gt;

&lt;p&gt;The same logic applies to arrays, since arrays are objects too:&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
const fruits = ["mango", "banana"];&lt;br&gt;
fruits.push("avocado");   // ✅ allowed — editing contents&lt;br&gt;
fruits[0] = "pineapple";  // ✅ allowed — editing contents&lt;br&gt;
// fruits = ["new", "list"]; // ❌ error — swaps the whole array reference&lt;br&gt;
🔓 let — same bottle rules, but the name can also switch bottles&lt;/p&gt;

&lt;p&gt;let allows everything const allows on contents, plus it lets the name walk away and point at a completely different bottle:&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
let aqua = { content: "water" };&lt;/p&gt;

&lt;p&gt;aqua.content = "wine";        // ✅ allowed — same bottle, refilled&lt;br&gt;
console.log(aqua);            // { content: "wine" }&lt;/p&gt;

&lt;p&gt;aqua = { content: "juice" };  // ✅ allowed — a whole NEW bottle, same name reused&lt;br&gt;
console.log(aqua);            // { content: "juice" }&lt;/p&gt;

&lt;p&gt;The two differences, side by side:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Refill the same bottle (edit contents)? Swap in a whole new bottle (reassign)?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;const   ✅ Yes ❌ No&lt;br&gt;
let ✅ Yes ✅ Yes&lt;/p&gt;

&lt;p&gt;🔑 One-line summary: both let you change what's inside the bottle. The only difference is whether the name is allowed to walk away and grab a different bottle entirely — const says no, let says go for it.&lt;/p&gt;

&lt;p&gt;🌀 Hoisting&lt;/p&gt;

&lt;p&gt;Before your code runs, JavaScript does a pass over the script and "hoists" (lifts) variable declarations to the top of their scope — but not the value assignment. Only the declaration moves up; the assignment stays where you wrote it.&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
console.log(a); // undefined — not an error!&lt;br&gt;
var a = 5;&lt;br&gt;
console.log(a); // 5&lt;/p&gt;

&lt;p&gt;Behind the scenes, this is treated like:&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
var a;           // declaration hoisted to the top, auto-set to undefined&lt;br&gt;
console.log(a);  // undefined&lt;br&gt;
a = 5;            // assignment happens where you originally wrote it&lt;br&gt;
console.log(a);  // 5&lt;/p&gt;

&lt;p&gt;let and const get hoisted too — but they don't default to undefined. Instead they sit in the Temporal Dead Zone (TDZ): the variable technically exists, but touching it before its declaration line is illegal.&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
console.log(b); // ❌ ReferenceError: Cannot access 'b' before initialization&lt;br&gt;
let b = 5;&lt;br&gt;
js&lt;br&gt;
{&lt;br&gt;
  // 🚧 TDZ starts here — b "exists" but is untouchable&lt;br&gt;
  console.log(b); // ❌ error, still in the dead zone&lt;/p&gt;

&lt;p&gt;let b = 5; // 🚧 TDZ ends here&lt;/p&gt;

&lt;p&gt;console.log(b); // ✅ 5, totally fine now&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;🔑 One-line summary: var gets hoisted and pre-filled with undefined. let/const get hoisted but stay locked in the dead zone until your code actually reaches their declaration line.&lt;/p&gt;

&lt;p&gt;🔁 Redeclaring&lt;br&gt;
js&lt;br&gt;
var x = 1;&lt;br&gt;
var x = 2; // ✅ allowed, messy but works&lt;/p&gt;

&lt;p&gt;let y = 1;&lt;br&gt;
// let y = 2; // ❌ error — can't redeclare a let in the same scope&lt;/p&gt;

&lt;p&gt;🎯 The verdict on all three: default to const. Switch to let only when you know the value (or the whole bottle) needs to change. Avoid var entirely in new code.&lt;/p&gt;

&lt;p&gt;🏷️ What is a data type?&lt;/p&gt;

&lt;p&gt;JavaScript sorts types into two families: primitive (simple, single values) and reference (complex, made of multiple values).&lt;/p&gt;

&lt;p&gt;🧱 Primitive types&lt;br&gt;
js&lt;br&gt;
let str = "hello";       // 🔤 String&lt;br&gt;
let num = 42;             // 🔢 Number&lt;br&gt;
let isTrue = true;        // ✅ Boolean&lt;br&gt;
let nothing = null;       // 🚫 Null — "empty on purpose"&lt;br&gt;
let notSet;                // ❓ Undefined — "not given a value yet"&lt;br&gt;
let big = 123n;             // 🐘 BigInt&lt;br&gt;
let sym = Symbol("id");     // 🔮 Symbol — guaranteed-unique value&lt;br&gt;
🧩 Reference types&lt;br&gt;
js&lt;br&gt;
let person = { name: "Brian", age: 22 }; // 🗂️ Object&lt;br&gt;
let fruits = ["mango", "banana"];          // 📋 Array (secretly an object)&lt;br&gt;
function greet() {}                          // ⚙️ Function (also technically an object)&lt;br&gt;
⚡ Special number values&lt;br&gt;
js&lt;br&gt;
console.log(1 / 0);        // Infinity&lt;br&gt;
console.log(-1 / 0);       // -Infinity&lt;br&gt;
console.log("abc" * 2);    // NaN&lt;br&gt;
console.log(typeof NaN);   // "number" 🤯&lt;/p&gt;

&lt;p&gt;🐛 Famous JS quirk: typeof null returns "object" — a decades-old bug that's now permanent. Just know it exists.&lt;/p&gt;

&lt;p&gt;🔍 Checking types&lt;br&gt;
js&lt;br&gt;
console.log(typeof "hi");         // "string"&lt;br&gt;
console.log(typeof 5);             // "number"&lt;br&gt;
console.log(typeof true);          // "boolean"&lt;br&gt;
console.log(typeof undefined);     // "undefined"&lt;br&gt;
console.log(typeof {});            // "object"&lt;br&gt;
console.log(typeof []);            // "object" — arrays are secretly objects&lt;br&gt;
console.log(typeof function(){});  // "function"&lt;br&gt;
🌊 Dynamic typing&lt;br&gt;
js&lt;br&gt;
let thing = "hello"; // starts as a String&lt;br&gt;
thing = 5;             // now it's a Number, JS doesn't complain&lt;br&gt;
⚙️ What is an operator?&lt;br&gt;
1️⃣ Arithmetic&lt;br&gt;
js&lt;br&gt;
let total = 5 + 3;      // 8&lt;br&gt;
let diff = 5 - 3;        // 2&lt;br&gt;
let product = 5 * 3;     // 15&lt;br&gt;
let split = 5 / 3;        // 1.666...&lt;br&gt;
let leftover = 5 % 3;      // 2 — modulus&lt;br&gt;
let power = 5 ** 2;         // 25 — exponent&lt;br&gt;
2️⃣ Assignment&lt;br&gt;
js&lt;br&gt;
let x = 10;&lt;br&gt;
x += 5;  // 15&lt;br&gt;
x -= 3;  // 12&lt;br&gt;
x &lt;em&gt;= 2;  // 24&lt;br&gt;
x /= 4;  // 6&lt;br&gt;
x %= 5;  // 1&lt;br&gt;
x *&lt;/em&gt;= 2; // 1&lt;br&gt;
3️⃣ Comparison&lt;br&gt;
js&lt;br&gt;
console.log(5 == "5");   // true — loose, ignores type&lt;br&gt;
console.log(5 === "5");  // false — strict, checks type too ✅ prefer this&lt;br&gt;
console.log(5 != "5");   // false&lt;br&gt;
console.log(5 !== "5");  // true ✅ prefer this&lt;br&gt;
console.log(5 &amp;gt; 3);        // true&lt;br&gt;
console.log(5 &amp;lt; 3);        // false&lt;br&gt;
console.log(5 &amp;gt;= 5);       // true&lt;br&gt;
console.log(5 &amp;lt;= 4);       // false&lt;br&gt;
4️⃣ Logical&lt;br&gt;
js&lt;br&gt;
let hasLaptop = true;&lt;br&gt;
let hasWifi = false;&lt;/p&gt;

&lt;p&gt;console.log(hasLaptop &amp;amp;&amp;amp; hasWifi); // false — AND&lt;br&gt;
console.log(hasLaptop || hasWifi); // true — OR&lt;br&gt;
console.log(!hasLaptop);            // false — NOT&lt;br&gt;
5️⃣ Increment / decrement&lt;br&gt;
js&lt;br&gt;
let count = 5;&lt;br&gt;
count++; // 6&lt;br&gt;
count--; // 5&lt;/p&gt;

&lt;p&gt;let n = 5;&lt;br&gt;
console.log(n++); // logs 5, THEN increments&lt;br&gt;
console.log(++n); // increments FIRST, then logs 7&lt;br&gt;
6️⃣ Ternary&lt;br&gt;
js&lt;br&gt;
let age = 20;&lt;br&gt;
let canVote = age &amp;gt;= 18 ? "Yes" : "No"; // "Yes"&lt;br&gt;
7️⃣ Nullish coalescing (??)&lt;br&gt;
js&lt;br&gt;
let username = null;&lt;br&gt;
let displayName = username ?? "Guest"; // "Guest"&lt;/p&gt;

&lt;p&gt;let score = 0;&lt;br&gt;
console.log(score ?? 100); // 0 — kept, since 0 isn't null/undefined&lt;br&gt;
console.log(score || 100); // 100 — || wrongly treats 0 as falsy ⚠️&lt;br&gt;
8️⃣ Optional chaining (?.)&lt;br&gt;
js&lt;br&gt;
let user = { profile: { name: "Brian" } };&lt;br&gt;
console.log(user?.profile?.name);    // "Brian"&lt;br&gt;
console.log(user?.settings?.theme);  // undefined — no crash 🙌&lt;br&gt;
9️⃣ Bitwise&lt;br&gt;
js&lt;br&gt;
console.log(5 &amp;amp; 1);  // 1 — AND&lt;br&gt;
console.log(5 | 1);  // 5 — OR&lt;br&gt;
console.log(5 ^ 1);  // 4 — XOR&lt;br&gt;
console.log(~5);      // -6 — NOT&lt;br&gt;
console.log(5 &amp;lt;&amp;lt; 1);  // 10 — shift left&lt;br&gt;
console.log(5 &amp;gt;&amp;gt; 1);  // 2 — shift right&lt;br&gt;
🔟 Keyword operators&lt;br&gt;
js&lt;br&gt;
console.log(typeof "hi");  // "string"&lt;/p&gt;

&lt;p&gt;let arr = [1, 2, 3];&lt;br&gt;
console.log(arr instanceof Array); // true&lt;/p&gt;

&lt;p&gt;let obj = { name: "Brian" };&lt;br&gt;
console.log("name" in obj); // true&lt;/p&gt;

&lt;p&gt;delete obj.name;&lt;br&gt;
console.log(obj); // {}&lt;br&gt;
1️⃣1️⃣ Comma operator&lt;br&gt;
js&lt;br&gt;
let a = (1 + 2, 3 + 4); // a = 7 — only the LAST value is kept&lt;br&gt;
🎁 TL;DR&lt;br&gt;
Category    Members&lt;br&gt;
🔤 Declarations   var, let, const&lt;br&gt;
🧱 Primitive types    String, Number, Boolean, Null, Undefined, BigInt, Symbol&lt;br&gt;
🧩 Reference types    Object, Array, Function&lt;br&gt;
⚙️ Operators    Arithmetic, Assignment, Comparison, Logical, Increment/Decrement, Ternary, Nullish Coalescing, Optional Chaining, Bitwise, Keyword ops, Comma&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
