Yep — even an empty array is truthy. Try this:
if ([]) console.log("true"); // It runs!
Then your “harmless” condition silently fails elsewhere. Been there? These tiny quirks can break production logic in the weirdest ways.
The Scope Chain Dance
var count = 1;
if (true) {
var count = 2;
}
console.log(count); // 2
Now switch to let or const and the behavior changes.
Lesson: If you're still casually using var in 2025 — you're skating on thin ice.
OOP vs Functional
Someone asked me: “Which is better — OOP or Functional?
My answer: Depends.
OOP helps when you're modeling real-world structures (ex: User, Order, Cart)
Functional shines when transforming data pipelines (ex: map(), filter(), reduce())
Real Use: I mixed both in a React-Redux app — OOP-style classes for config, FP-style for transformation — and it worked beautifully.
The DOM: Knowing It vs Using It
Many devs use JS or React to manipulate the DOM — but few understand how it really works under the hood.
document.body.children[0].textContent;
Looks old-school? It once helped me debug a script before React mounted.
Why it matters: DOM knowledge is critical when:
- Tuning performance
- Fixing bugs in third-party scripts
- Understanding how React actually mounts
JSON.stringify() vs JSON.parse()
const data = JSON.stringify({ price: 100 });
const parsed = JSON.parse(data);
Clean, right? Now try:
JSON.parse(undefined);
Real APIs don’t always come wrapped with love and structure.
Lesson: Always validate before parsing.
Use try...catch:
try {
const safeParsed = JSON.parse(data);
} catch (error) {
console.error("Parsing failed:", error);
}
Final Thought
JavaScript doesn’t just run — it behaves. Sometimes… unexpectedly. And knowing those behaviors is what separates a dev from a debugger.
What’s your most “Wait… what just happened?” JS moment?
Drop your logic bugs, type coercion fails, or memory leaks below , Let’s laugh, cry, and learn together.
Top comments (0)