🔥 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
"JavaScript: When prototype is not an object"
More Relevant Posts
-
🍏 JS Daily Bite #10 — JavaScript Prototype Chains: A Full Comparison Master JavaScript's prototype-based inheritance system by exploring ways to create and manipulate prototype chains, their trade-offs, and best practices. 🏗️ Methods for Creating Prototype Chains: 1️⃣ Object Literal Syntax with __proto__ ✅ Standardized, optimized, more performant than Object.create() ✅ Ergonomic for declaring properties at creation ⚠️ Fails silently when pointing to non-objects 2️⃣ Constructor Functions ✅ Fast, standard, JIT-optimizable ⚠️ Methods are enumerable by default, inconsistent with class syntax ⚠️ Error-prone for longer inheritance chains 3️⃣ Object.create() ✅ Direct prototype setting at creation ✅ Can create objects with null prototype ⚠️ Verbose, error-prone, potentially slower than literals 4️⃣ Classes (ES6+) ✅ Ideal for complex inheritance with readability and maintainability ✅ Supports private elements ⚠️ Less optimized than traditional constructors 🔧 Mutating Existing Prototype Chains: 1️⃣ Object.setPrototypeOf() ✅ Modify the prototype of existing objects ⚠️ Can disrupt engine optimizations 💡 Best practice: set prototype during object creation 2️⃣ The __proto__ Accessor ⚠️ Fails silently with non-objects ⚠️ Non-standard and deprecated 💡 Recommendation: use Object.setPrototypeOf() instead ⚡ Performance Considerations: 1️⃣ Prototype Chain Lookup Costs Deep chains slow property access Non-existent properties traverse the entire chain All enumerable properties in the chain are iterated 2️⃣ Checking Own Properties Use hasOwnProperty() or Object.hasOwn() Don’t rely solely on undefined checks 🔜 Next in the Series: Enumerability and ownership of properties #JavaScript #JSDailyBite #WebDevelopment #Programming #LearnToCode #Prototypes #Inheritance #SoftwareEngineering #FrontendDevelopment #JSFundamentals #TechEducation
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
-
🍏 JS Daily Bite #9 — Understanding Function Prototypes Every function in JavaScript has a special property called prototype — the foundation of how inheritance and object construction work in the language. 🔍 The Function Prototype Property All functions (except arrow functions) have a default prototype property Arrow functions ❌ do not have a prototype The prototype object includes a constructor property that points back to the function Each prototype object’s [[Prototype]] links up to Object.prototype 🧱 Adding Properties to Prototypes You can attach properties or methods to a function’s prototype to make them automatically available to all instances created with that function. This is a memory-efficient way to share behavior across instances! ⚡️ 🧩 Creating Instances with new When you use the new operator: A new object is created Its [[Prototype]] is set to the function’s prototype property Instance-specific properties are initialized Shared methods are inherited through the prototype chain 🧭 How Property Lookup Works When accessing a property: JavaScript checks the object itself If not found, it climbs the prototype chain ([[Prototype]]) The search continues until Object.prototype If still not found, the result is undefined 🧠 Key Takeaways Instance properties override prototype properties Prototype properties are shared across all instances The chain always ends at Object.prototype.[[Prototype]] === null Mastering this mechanism is essential for deep JavaScript understanding 💪 🔜 Next in the Series → Comparing Ways to Create and Mutate the Prototype Chain #JavaScript #WebDevelopment #Programming #TechEducation #LearnToCode #SoftwareDevelopment #JSInsights #CodeLearning #Frontend #JSFundamentals #Prototypes #JSDailyBite
To view or add a comment, sign in
-
💡 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
To view or add a comment, sign in
-
🍏 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
-
💡 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
-
*5 Things I Wish I Knew When Starting JavaScript 👨💻* Looking back, JavaScript was both exciting and confusing when I started. Here are 5 things I wish someone had told me earlier: *1. `var` is dangerous. Use `let` and `const`* – `var` is function-scoped and can lead to unexpected bugs. `let` and `const` are block-scoped and safer. *2. JavaScript is asynchronous* – Things like `setTimeout()` and `fetch()` don’t behave in a straight top-down flow. Understanding the *event loop* helps a lot. *3. Functions are first-class citizens* – You can pass functions as arguments, return them, and even store them in variables. It’s powerful once you get used to it. *4. The DOM is slow – avoid unnecessary access* – Repeated DOM queries and manipulations can hurt performance. Use `documentFragment` or batch changes when possible. *5. Don’t ignore array methods* – `map()`, `filter()`, `reduce()`, `find()`… they make code cleaner and more readable. I wish I started using them sooner. 💡 *Bonus Tip:* `console.log()` is your best friend during debugging! If you’re starting out with JS, save this. And if you're ahead in the journey — what do *you* wish you knew earlier? #JavaScript #WebDevelopment #CodingJourney #Frontend #LearnToCode #DeveloperTips
To view or add a comment, sign in
-
🚀 Understanding Functions in JavaScript — The Building Blocks of Logic! While exploring JavaScript, I realized that functions are at the heart of writing clean, reusable, and organized code. They help us break down complex logic into smaller, manageable parts. Here’s a quick breakdown of different types of functions in JavaScript 👇 🟢 1. Function Declaration function greet() { console.log("Hello, World!"); } ✅ Hoisted — can be called before their definition. 🟣 2. Function Expression const greet = function() { console.log("Hello, World!"); }; ⚠️ Not hoisted — must be defined before use. 🔵 3. Arrow Function (ES6) const greet = () => console.log("Hello, World!"); 💡 Short, modern syntax — great for callbacks and concise logic. 🟠 4. Anonymous Function Used without a name, often inside event handlers or callbacks. setTimeout(function() { console.log("Executed after 2 seconds"); }, 2000); 🔴 5. Immediately Invoked Function Expression (IIFE) Runs immediately after it’s defined. (function() { console.log("IIFE executed!"); })(); Useful for creating isolated scopes. 🟢 6. Higher-Order Function A function that takes another function as an argument or returns one. function operate(a, b, callback) { return callback(a, b); } operate(2, 3, (x, y) => x + y); // Output: 5 🔁 Common in methods like .map(), .filter(), and .reduce(). ✨ Functions are like the brain of your JavaScript code — they decide how everything works together! 💬 What’s your favorite type of JavaScript function and why? Let’s discuss how each type fits into modern JS coding! #JavaScript #WebDevelopment #Frontend #Coding #Programming #LearningJourney
To view or add a comment, sign in
-
🧠 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐜𝐚𝐧 𝐛𝐞 𝐰𝐞𝐢𝐫𝐝. 𝐄𝐬𝐩𝐞𝐜𝐢𝐚𝐥𝐥𝐲 𝐰𝐡𝐞𝐧 𝐢𝐭 𝐜𝐨𝐦𝐞𝐬 𝐭𝐨 𝐭𝐲𝐩𝐞 𝐜𝐨𝐞𝐫𝐜𝐢𝐨𝐧. You write a simple expression. Expect a number. Get a string. Or worse NaN. Let’s walk through 5 real examples that trip up even experienced devs and what they actually return. 👇 🔹 1 + "2" + "2" Returns: "122" Why? 1 + "2" → "12" (number + string = string) "12" + "2" → "122" 🔹 1 + +"2" + "2" Returns: "32" Why? +"2" → 2 1 + 2 → 3 3 + "2" → "32" 🔹 1 + -"1" + "2" Returns: "02" Why? -"1" → -1 1 + (-1) → 0 0 + "2" → "02" 🔹 +"1" + "1" + "2" Returns: "112" Why? +"1" → 1 1 + "1" → "11" "11" + "2" → "112" 🔹 "A" - "B" + 2 Returns: NaN Why? "A" - "B" → NaN NaN + 2 → still NaN 💡 Key takeaways: - Unary + converts strings to numbers. - Mixing strings and numbers with + leads to string concatenation. - Non-numeric strings in math return NaN. - Always check your operand types before using +, -, or ==. If you’ve ever been confused by JavaScript’s quirks, you’re not alone. Type coercion is one of the most common sources of bugs in JS. Want more no fluff JavaScript breakdowns? Follow me here 👉 Sumit Mitra JavaScript can be weird. Especially when it comes to type coercion. #JavaScript #WebDevelopment #Frontend #CodingTips #TypeCoercion #JS #SoftwareEngineering
To view or add a comment, sign in
-
Today's Topic: Promise Chaining in JavaScript In JavaScript, Promise chaining allows you to execute asynchronous tasks one after another, ensuring that each step waits for the previous one to finish. Instead of nesting callbacks (callback hell ), promises make your code cleaner and easier to maintain. Example: function step1() { return new Promise((resolve) => { setTimeout(() => { console.log("Step 1 completed ✅"); resolve(10); }, 1000); }); } function step2(value) { return new Promise((resolve) => { setTimeout(() => { console.log("Step 2 completed ✅"); resolve(value * 2); }, 1000); }); } function step3(value) { return new Promise((resolve) => { setTimeout(() => { console.log("Step 3 completed ✅"); resolve(value + 5); }, 1000); }); } // Promise Chaining step1() .then(result => step2(result)) .then(result => step3(result)) .then(finalResult => console.log("Final Result:", finalResult)) .catch(error => console.error("Error:", error)); ✅ Output (after 3 seconds): Step 1 completed ✅ Step 2 completed ✅ Step 3 completed ✅ Final Result: 25 Each .then() runs after the previous promise resolves — making async flow easy to read and manage. --- 🔖 #JavaScript #WebDevelopment #PromiseChain #AsyncProgramming #CodingTips #FrontendDevelopment #Developers #JSConcepts #CodeLearning #100DaysOfCode #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