Day 3: The Day JavaScript Started Acting Weird

Alright, day 3. Let me be honest with you — the first two days I felt smart. Like "oh, this coding thing isn't so bad." Day 3 humbled me.
I'm learning through my web development course, and today sir basically said "remember those simple boxes? Forget simple." And introduced the complicated family.
Boxes that hold... everything?
So far every variable held ONE thing. One number. One string. Done.
Then sir wrote this:
let arr = [10, 20, 50, "ali", "mohit"];
Numbers AND names. In the same box. Together. My first thought was "wait, that's allowed??" Turns out yes. It's called an Array — just a list, in order. Like a train. Every bogie has a number, bogies stay in order.
Except — and this is where I laughed out loud — programmers count from zero. The FIRST bogie is bogie number 0. I don't know who decided this. I just work here.
Then sir did this:
console.log(typeof arr); // "object"
I stared at my screen. An array... is an object? Sir just smiled. "Arrays are objects wearing a trench coat." Okay sir. Okay.
Then came Objects (capital O, different thing). Instead of numbered bogies, every value gets a name tag:
let obj = { user_name: "Ali", account_number: 31242314213, balance: 420 };
This one actually made sense to me immediately. It's like a form. Name: Ali. Account number: that. Balance: 420. You want the balance? Ask for it by name. No counting bogies.
And Functions — I'll be real with you, we only touched these. A function is a recipe you write once and reuse. Like instead of explaining how to make chai every single time, you write it down once and just say "make chai." We'll go deep later. Today was already a lot.
The part where JavaScript lies to you
Okay so. Yesterday we learned values have "species." Today I learned JavaScript secretly converts one species into another when you're not looking. It's called type conversion. Or coercion, which is just a fancy word for converting.
Sometimes you ask for it:
Number("100") // 100. Fair. The text "100" becomes the number 100.
And sometimes JavaScript just... decides:
Number("100xs") // NaN
NaN means "Not a Number." It's what JavaScript gives you when it tries to do math and fails. It's basically JavaScript throwing its hands up going "I don't know, man."
Look at this list. Really look at it.
Number(null) gives 0. So "nothing" equals zero. Fine.
Number(undefined) gives NaN. So "not defined" breaks math entirely.
And my personal favorite — Boolean(" ") is true. That's a single SPACE. Invisible. Nothing you can see. And JavaScript goes "yep, that's truthy." Meanwhile my motivation on Monday mornings? Falsy.
I found the clearest explanation of all this on Reddit and dev.to, and it clicked for me instantly, so here it is: the + sign has two personalities. If there's a string anywhere near it, + becomes GLUE. It just sticks things together:
"2" + "2" // "22" — glue, not math
But - only knows math. Which gives us the legendary:
"2" + "2" - "2" // 20
Go left to right. "2"+"2" becomes "22" (glue). Then "22"-"2" — JavaScript panics, converts both to numbers — 22-2 — 20.
This exact thing is a famous meme on r/ProgrammerHumor. Thousands of people have stared at it the way I did. Welcome to the club.
The ++ thing that broke me
Last topic. Operators — + - * /, the symbols that do things. Mostly normal. BODMAS came back from school (brackets first, I actually used it):
(((6*(3+18))/6)-9) // 12
And % gives you the remainder. 20 % 3 is 2. Twenty rotis, three people, two left over. Nobody cares about % until the day they really, really need it.
But then. Then came ++.
let sum = 20;
let total = sum++;
What do you think total is? 21, right? Because sum++ means "add one"?
Nope. total is 20.
Because sum++ takes a photo FIRST and increments LATER. It grabs 20, hands it to total, and THEN sum becomes 21. Like that friend who says "I'll do it later" and means it.
But:
let sum = 20;
let total = ++sum;
NOW total is 21. Because ++sum increments FIRST, then hands it over. Same two characters. Different side. Different answer.
I genuinely sat staring at this for ten minutes. Ten. Minutes.
Anyway. Once I recovered:
i++ and i += 1 do the same thing. One of them just wears a tuxedo. (via lesjoiesducode.fr)
So that's day 3. Arrays, objects, JavaScript lying about types, and the ++ that gaslit me.
Tomorrow is == vs === and I'm honestly a little scared. See you there.



