💡 Why Almost Everything in JavaScript is an “Object” If you’ve ever heard “everything in JavaScript is an object”, you’re not alone — and you’re almost right. 😄 Here’s the real story 👇 JavaScript is a prototype-based language, where most things — from arrays to functions — are built on top of objects. This makes JavaScript incredibly flexible and dynamic. ✅ Numbers, strings, and booleans Even these primitives temporarily behave like objects when you access methods: "hello".toUpperCase(); // works because JS wraps it in a String object ✅ Functions and Arrays They’re technically objects too — with callable or iterable behavior added on top. That’s why you can do things like: myFunc.customProp = 42; ✅ Everything inherits from Object.prototype It’s the ultimate ancestor — where common methods like toString() and hasOwnProperty() live. 🧠 Key Takeaway JavaScript’s design treats almost everything as an object so it can: Extend behavior dynamically Support inheritance via prototypes Provide consistency across data types But remember: Primitives (null, undefined, number, string, boolean, symbol, bigint) are not true objects — they just act like them when needed. 🚀 TL;DR In JavaScript, objects are the foundation. Almost everything is built on top of them — it’s what gives JS its power, flexibility, and sometimes… confusion. 😅 #JavaScript #WebDevelopment #Frontend #React #Coding #Learning
How JavaScript treats almost everything as an object
More Relevant Posts
-
🍏 JS Daily Bite #7 🧬 JavaScript Inheritance: Understanding the Prototype Chain JavaScript's approach to inheritance is unique — and understanding it is key to mastering the language. 🚀 What is the Prototype Chain? JavaScript objects are dynamic collections of properties ("own properties"). But here's where it gets interesting: every object also has a link to a prototype object. When you try to access a property, JavaScript doesn't just look at the object itself — it searches up the prototype chain until it either finds the property or reaches the end of the chain. 🧩 🔑 Key Concepts to Know: [[Prototype]] is the internal link to an object's prototype, accessible via Object.getPrototypeOf() and Object.setPrototypeOf(). Don’t confuse obj.__proto__ with func.prototype — the latter specifies what prototype will be assigned to instances created by a constructor function. In object literals, you can use { __proto__: c } to set the prototype directly. 🧠 The “Methods” Twist: JavaScript doesn’t have methods in the traditional class-based sense. Functions are just properties that can be inherited like any other. And here's a critical detail: when an inherited function executes, this points to the inheriting object — not the prototype where the function is defined. ⚡ 💡 Why This Matters: Understanding prototypes is essential for working with JavaScript's object model, debugging inheritance issues, and leveraging modern class syntax (which is really just syntactic sugar over prototypes). 👉 Next up: Constructors — how JavaScript creates and links objects during instantiation! #JavaScript #JSDailyBite #WebDevelopment #Programming #FrontendDevelopment #SoftwareEngineering #LearnToCode #TechEducation #CodeNewbie #Developers #100DaysOfCode
To view or add a comment, sign in
-
Today I Learned: Iterators & Generators in JavaScript One of the most interesting parts of modern JavaScript is how it handles iteration, and today I finally understood how Iterators and Generators work under the hood! 🧠 1. Iterators An iterator is simply an object that defines how to step through a sequence, one value at a time. It follows the pattern: const iterator = [10, 20, 30][Symbol.iterator](); console.log(iterator.next()); // { value: 10, done: false } console.log(iterator.next()); // { value: 20, done: false } Each call to .next() gives you the next value until done: true. ⚙️ Generators A generator function (defined with function*) automatically creates an iterator for you. function* greet() { yield "Hi"; yield "Hello"; yield "Hey"; } const it = greet(); console.log(it.next().value); // Hi console.log(it.next().value); // Hello What’s cool is that you can pause and resume function execution! 🔥 💡 Key Takeaway: Iterators let you take control of how data is accessed. Generators make it easier to build your own iterators — letting you write asynchronous, lazy, and powerful code structures. Every day, I’m realising how deep JavaScript really is — and how beautiful its design becomes when you understand what’s happening under the hood. #JavaScript #WebDevelopment #LearningInPublic #BackendDevelopment #ES6
To view or add a comment, sign in
-
🔥 JavaScript: When “prototype” is NOT an object 👀 We all learn early — > “Every function in JavaScript has a prototype property that is an object.” But JavaScript loves exceptions 😏 Here are some surprising cases where prototype is not an object 👇 RegExp.prototype // → /(?:)/ Array.prototype // → [] Function.prototype // → ƒ () {} Number.prototype // → Number {} String.prototype // → String {} Boolean.prototype // → Boolean {} Symbol.prototype // → Symbol {} BigInt.prototype // → BigInt {} 💡 Notice something? Some of these are functions, arrays, or even regular expressions! That’s because their prototypes are actual instances of their types, not plain objects — so that all instances inherit their core methods directly. For example: Array.prototype.push === [].push // true ✅ RegExp.prototype.test === /abc/.test // true ✅ So next time you assume prototype is always {}, remember — JS is full of living examples 😉 --- 💬 Have you ever found a weird prototype behavior while debugging? Drop it in the comments — let’s break more JS myths together! ⚙️ #JavaScript #WebDevelopment #LearningEveryday #Frontend
To view or add a comment, sign in
-
🚀 Day 30/50 – Function Currying in JavaScript Think of Function Currying like building a relationship. You don’t propose directly 😅 First comes the “Hi Hello 👋” phase → then friendship ☕ → and finally… the proposal ❤️ In JavaScript, instead of passing all arguments at once, Function Currying lets us pass them step by step, each step returning a new function until the final output is achieved. Here’s a simple code analogy from my video: function proposeTo(crush) { return function (timeSpent) { return function (gift) { return `Dear ${crush}, after ${timeSpent} of friendship, you accepted my ${gift}! 🥰`; }; }; } console.log(proposeTo("Sizuka")("3 months")("red rose 🌹")); Each function takes one argument and returns another function — making the code modular, flexible, and easy to reuse. 👉 This is Function Currying — one argument, one step, one perfect result. 🎥 Watch the full short video here: 🔗 https://lnkd.in/g-NkeYBc --- 💡 Takeaway: Function Currying isn’t just a JavaScript trick — it’s a powerful pattern for cleaner, more composable functions that enhance reusability and maintainability in modern frontend code. --- Would love to know: 👉 What’s your favorite JavaScript concept that clicked instantly when you saw it explained simply? #javascript #frontenddevelopment #webdevelopment #coding #programming #softwareengineering #learnjavascript #100daysofjavascript #techsharingan #developers #careergrowth
To view or add a comment, sign in
-
🔥 Understanding the Call Stack in JavaScript — The Backbone of Execution Ever wondered how JavaScript keeps track of what to run, when to run, and when to stop? The answer lies in one simple but powerful concept: 🧠 The Call Stack Think of the Call Stack as a stack of tasks where JavaScript executes your code line by line, following the LIFO rule — Last In, First Out. 🧩 How it works: Whenever you call a function → it goes on top of the stack When the function finishes → it gets popped out If the stack is busy → everything waits If it overflows → boom 💥 “Maximum call stack size exceeded” 🕹 Simple Example: function a() { b(); } function b() { console.log("Hello!"); } a(); Execution Order: a() → b() → console.log() → end All handled beautifully by the Call Stack. 🎬 Imagine a scene: A waiter takes orders one at a time. He won’t serve the next customer until he completes the current order. That’s your Call Stack — disciplined and strict. --- 🚀 Why You Should Understand It To debug errors efficiently To write non-blocking code To understand async behavior To avoid stack overflow bugs Mastering the Call Stack is the first big step toward mastering JavaScript’s execution model. --- #javascript #webdevelopment #frontend #reactjs #reactdeveloper #nodejs #softwareengineering #programming #js #developers #codingtips #learnjavascript #tech
To view or add a comment, sign in
-
-
💡 Day 8/50 – Mastering JavaScript’s Subtle Behaviors 🚀 In JavaScript, sometimes the hardest bugs aren’t syntax errors — they’re “Wait… why did that happen?” moments 😅 Today’s Day 8 questions were built around 3 such moments that every developer faces: --- 🧬 1️⃣ Prototype Inheritance — The Hidden Chain When you create an object using Object.create(), it doesn’t copy properties from the parent… it links to it. That means if a property isn’t found in the child, JavaScript looks up the prototype chain to find it. 👉 This “lookup behavior” often confuses devs who expect a fresh, independent copy. So the next time you’re debugging unexpected data access, remember — It might not be your object, it might be its prototype! --- 🧠 2️⃣ The Mystery of Double .bind() You might think rebinding a function twice changes its context again. But nope! Once you bind a function in JavaScript, it’s permanently bound. Calling .bind() again has no effect — the context (the value of this) stays fixed to the first bind. 💡 Why? Because bind() returns a new function with the this value locked in forever. --- 🧩 3️⃣ Type Coercion + Function Conversion Ever tried adding a function to a string like add + "text"? JavaScript doesn’t crash — it converts your function to a string using its internal toString() method! The result isn’t math; it’s a combination of type coercion and string representation. This is one of those delightful quirks that makes JS both fun and… slightly unhinged 😄 --- 📽️ Watch Day 8 Reel: https://lnkd.in/gBHYWgyi Because once you understand the why, no interviewer can trick you again 😉 #JavaScript #FrontendDevelopment #WebDevelopment #JSInterviewQuestions #CodingChallenge #TechLearning #SoftwareEngineering #Techsharingan #Developers
To view or add a comment, sign in
-
💡 Deep Dive into JS Concepts: How JavaScript Code Executes ⚙️ Ever wondered what really happens when you hit “Run” in JavaScript? 🤔 Let’s take a simple, visual deep dive into one of the most powerful JS concepts — ✨ The Execution Context & Call Stack! 🧠 Step 1: The Global Execution Context (GEC) When your JS file starts, the engine (like Chrome’s V8) creates a Global Execution Context — the environment where everything begins 🌍 It has two phases: 🧩 Creation Phase Memory allocated for variables & functions Variables set to undefined (Hoisting!) Functions fully stored in memory ⚡ Execution Phase Code runs line by line Variables get actual values Functions are executed 🚀 🔁 Step 2: Function Execution Context (FEC) Every time a function is called, a brand-new Execution Context is created 🧩 It also runs through creation + execution phases. When the function finishes — it’s removed from memory 🧺 🧱 Step 3: The Call Stack Think of the Call Stack like a stack of plates 🍽️ Each function call adds (pushes) a new plate When done, it’s removed (popped) JS always executes the topmost plate first Example 👇 function greet() { console.log("Hello"); } function start() { greet(); console.log("Welcome"); } start(); 🪜 Execution Order: 1️⃣ GEC created 2️⃣ start() pushed 3️⃣ greet() pushed 4️⃣ greet() popped 5️⃣ start() popped 6️⃣ GEC popped ✅ ⚙️ Step 4: Quick Recap 🔹 JS runs inside Execution Contexts 🔹 Each function = its own mini world 🔹 Contexts live inside the Call Stack 🔹 Each runs through Creation → Execution “JavaScript doesn’t just run line-by-line — it builds a whole world (context) for your code to live and execute inside.” 🌐 #javascript #webdevelopment #frontend #developers #learnjavascript #executionscontext #callstack #jsengine #programming #deeplearning
To view or add a comment, sign in
-
-
Day 73 of #100DaysOfCode Today I dove into Object-Oriented JavaScript specifically Classes and the this keyword. In JavaScript, a class is like a blueprint for creating multiple objects with shared structure and behavior. It can include: A constructor() → initializes properties Methods → define actions for class instances Example: class Dog { constructor(name) { this.name = name; } bark() { console.log(`${this.name} says woof!`); } } const dog = new Dog("Gino"); dog.bark(); // Gino says woof! Here, this refers to the current object instance. In methods, it gives access to that object’s properties and behaviors. Key takeaways 🧠 Classes make code reusable and modular. this ensures context, it points to who is calling the method. Arrow functions don’t create their own this; they inherit from their scope. Mastering these two concepts is a huge step toward writing cleaner, scalable JavaScript.
To view or add a comment, sign in
-
Demystifying the Prototype in JavaScript If there’s one concept that confuses most developers (even experienced ones), it’s the Prototype. Unlike traditional class-based languages, JavaScript uses prototypal inheritance — meaning objects can inherit directly from other objects. Every JS object has a hidden reference called its prototype, and this is what makes inheritance possible. 🔹 How It Works When you access a property like obj.prop1: 1️⃣ JS first checks if prop1 exists on the object itself. 2️⃣ If not, it looks at the object’s prototype. 3️⃣ If still not found, it continues up the prototype chain until it either finds it or reaches the end. So sometimes a property seems to belong to your object — but it actually lives further down the chain! Example const person = { firstname: "Default", lastname: "Default", getFullName() { return this.firstname + " " + this.lastname; } }; const john = Object.create(person); john.firstname = "John"; john.lastname = "Doe"; console.log(john.getFullName()); // "John Doe" Here’s what happens: JS looks for getFullName on john. Doesn’t find it → checks person (its prototype). Executes the method with this referring to john. Key Takeaways The prototype is just a hidden reference to another object. Properties are looked up the prototype chain until found. The this keyword refers to the object calling the method, not the prototype. Avoid using __proto__ directly — use Object.create() or modern class syntax. One-liner: The prototype chain is how JavaScript lets one object access properties and methods of another — simple, flexible, and core to the language. If you found this helpful, follow me for more bite-sized explanations on JavaScript, React, and modern web development #JavaScript #WebDevelopment #Frontend #React #TypeScript #Coding #LearningInPublic #SoftwareEngineering #TechEducation #WebDevCommunity
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development