JavaScript taught me something cool today 🤔 You know how we write classes in JavaScript? Turns out, JS doesn't actually have "real" classes like Java or C++. It's a Prototype-based language wearing a class costume! ✨ ➡️When we write this: class Person { constructor(name) { this.name = name; } greet() { return `Hello, I'm ${this.name}`; } } ➡️ JavaScript actually does this: function Person(name) { this.name = name; } Person.prototype.greet = function() { return `Hello, I'm ${this.name}`; } 🔺 Same result, different reality! The class syntax is just syntactic sugar to make it look familiar. Under the hood, everything still runs on Prototypes, implementing Inheritance, Encapsulation, Abstraction and Polymorphism in its own unique way. 📌 Understanding this helped me: • Finally get why this acts weird sometimes • Debug inheritance issues way faster • Realize methods live on the prototype (memory efficient!) 🖊️ Anyone else had this "wait, what?" moment with JavaScript? 😅 #JavaScript #WebDevelopment #LearningToCode
JavaScript classes are just syntactic sugar for prototypes
More Relevant Posts
-
JavaScript Deep Dive: The Story Behind null Today, I explored the origins of one of JavaScript’s quirkiest features — null. It turns out this little value has a surprising history! 🔹 Where it Began: JavaScript was created in 1995 by Brendan Eich in just 10 days. Since it was inspired by Java, null was included to represent the intentional absence of any object — just like in Java. 🔹 The Famous Bug: Ever wondered why this happens? typeof null // "object" This result is actually due to an early implementation bug. null was given the same type tag as objects — and fixing it would have broken lots of existing code. So it stayed. 😅 🔹 null vs undefined: JavaScript defines two empty values: null: Intentionally empty (set by programmers) undefined: Automatically assigned by JavaScript for missing or uninitialized values This distinction has confused developers for decades! 🔹 Standardized in ECMAScript: Both null and undefined were formalized in the first ECMAScript standard (1997), cementing their roles in the language. 💡 Takeaway: JavaScript's null is a great example of how early design decisions — even mistakes — can shape a language's future. Knowing its history helps us write code with more clarity and intention. Let’s keep learning the story behind the code! 🎯 #JavaScript #LearningInPublic #WebDevelopment #HistoryOfJS #Programming #10000Coders #CodeNewbie
To view or add a comment, sign in
-
-
Recently, I was asked a JavaScript question in an interview that honestly stumped me at first 😅 — it really tested my core JS understanding. 💡 Question: “Why does JavaScript allow you to add functions to the Math library, but Java does not?” At that moment, I couldn’t answer it. Later, when I looked it up, I found the explanation really interesting 👇 In JavaScript, Math is just a normal object — dynamic and extendable. You can add new methods like this: Math.square = function(x) { return x * x; }; console.log(Math.square(5)); // ✅ 25 But in Java, Math is a final class with static methods — you can’t inherit or modify it. This keeps the system stable and predictable, which aligns with Java’s strong type and compile-time safety philosophy. I found this question such a great reminder of how JavaScript’s flexibility and Java’s rigidity come from totally different design goals. #JavaScript #Java #InterviewQuestions #LearningEveryday #Developers #Programming
To view or add a comment, sign in
-
🚀 𝐔𝐧𝐝𝐞𝐫𝐬𝐭𝐚𝐧𝐝𝐢𝐧𝐠 𝐓𝐲𝐩𝐞𝐬 𝐨𝐟 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐢𝐧 𝐣𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 🚀 In JavaScript, functions can be written in several ways, and each type has its own purpose. Function Declaration is the basic way to create a function using the function keyword. It can be called before it’s defined. ✨ 𝐍𝐚𝐦𝐞𝐝 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A regular function with a name, defined using the function keyword. It can be called multiple times and improves code readability. 🕒 𝐀𝐧𝐨𝐧𝐲𝐦𝐨𝐮𝐬 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A function without a name, often used inside other functions as callbacks like in setTimeout or addEventListener. ⚡ 𝐀𝐫𝐫𝐨𝐰 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A modern and shorter syntax that makes code cleaner and inherits this from its surrounding scope. 🚀 𝐈𝐈𝐅𝐄 (𝐈𝐦𝐦𝐞𝐝𝐢𝐚𝐭𝐞𝐥𝐲 𝐈𝐧𝐯𝐨𝐤𝐞𝐝 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐄𝐱𝐩𝐫𝐞𝐬𝐬𝐢𝐨𝐧) — A function that runs immediately after it’s defined. It’s useful to keep variables private and avoid polluting the global scope. 🧠 𝐇𝐢𝐠𝐡𝐞𝐫-𝐎𝐫𝐝𝐞𝐫 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A function that takes another function as an argument or returns a function. This is often used in functional programming, like with map, filter, or forEach. 🏗️ 𝐂𝐨𝐧𝐬𝐭𝐫𝐮𝐜𝐭𝐨𝐫 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A special type of function used with the new keyword to create and initialize objects. 🌟 Great insights from Codexign, worth sharing! #javascript #js #softwaredeveloper #JavaScriptTips #Functions #FunctionsInJavaScript #JSTutorial #webdevelopment #frontenddevelopment #CodingTips #JavaScriptDeveloper #JavaScriptTypes #Programming #Coding #JSLearning #JSTypes #education #LearnJavaScript #technology #w3schools #careers
To view or add a comment, sign in
-
Well-Known Symbols and Their Applications Comprehensive Guide to Well-Known Symbols in JavaScript and Their Applications Introduction JavaScript, an essential language for web development, has an ecosystem that is rich in features and often compared to Java, C#, or Python for its dynamic capabilities. One of the lesser-known yet powerful features of the language is its "Well-Known Symbols." Introduced in ECMAScript 2015 (ES6), these symbols serve as unique keys for object properties and facilitate advanced programming concepts, including meta-programming. This article delves into the historical context, technical intricacies, practical applications, performance considerations, and advanced use-cases of Well-Known Symbols, ultimately providing a robust guide for experienced developers. The concept of symbols in JavaScript stems from the need for unique identifiers that do not clash with property names in objects. Prior to ES6, developers employed various workarounds like string concatenation or object literals, eac https://lnkd.in/gn2kiRnA
To view or add a comment, sign in
-
Well-Known Symbols and Their Applications Comprehensive Guide to Well-Known Symbols in JavaScript and Their Applications Introduction JavaScript, an essential language for web development, has an ecosystem that is rich in features and often compared to Java, C#, or Python for its dynamic capabilities. One of the lesser-known yet powerful features of the language is its "Well-Known Symbols." Introduced in ECMAScript 2015 (ES6), these symbols serve as unique keys for object properties and facilitate advanced programming concepts, including meta-programming. This article delves into the historical context, technical intricacies, practical applications, performance considerations, and advanced use-cases of Well-Known Symbols, ultimately providing a robust guide for experienced developers. The concept of symbols in JavaScript stems from the need for unique identifiers that do not clash with property names in objects. Prior to ES6, developers employed various workarounds like string concatenation or object literals, eac https://lnkd.in/gn2kiRnA
To view or add a comment, sign in
-
JavaScript isn't an OOP language. Many beginners think of JavaScript classes as “classical OOP”, similar to Java or C++. But here’s the fascinating part: ✅ JavaScript doesn’t have classical inheritance. ✅ Classes in JS are syntactic sugar over its prototype system. Here’s what actually happens: class User { greet() { console.log('Hello!'); } } const u = new User(); u.greet(); When you create `u`, JS doesn’t copy `greet` into `u`. Instead: - `u` has a hidden reference `__proto__` pointing to `User.prototype`. - The method `greet` lives on the prototype. - JS looks up the prototype chain when a method is called. You can even add new methods dynamically: User.prototype.sayBye = () => console.log('Bye!'); u.sayBye(); 💡 Takeaway: Understanding prototypes is the key to truly mastering JS OOP. Classes are just a convenient way to write what prototypes already do. #JavaScript #WebDevelopment #OOP #Prototypes #LearningInPublic
To view or add a comment, sign in
-
🛑 Still using this to deep clone objects in JavaScript? JSON.parse(JSON.stringify(obj)) It works… until it doesn’t 😅 It breaks with: ❌ Dates (turn into strings) ❌ Maps / Sets (lost completely) ❌ undefined & functions (removed) ❌ Circular references (throws error) JavaScript now has a modern, safer solution: structuredClone(obj) ✨ Supports circular references ✨ Preserves Date, Map, Set, RegExp ✨ Faster & built-in in modern JS/Node I wrote a simple blog with easy examples explaining why this matters, including a quick view of Shallow vs Deep cloning so the concept is crystal clear even for beginners. 🔗 Read it here: https://lnkd.in/dVcGiNwv #JavaScript #WebDevelopment #Programming #NodeJS #TypeScript #JSTips #CleanCode #SoftwareEngineering #Developers #WebDev #CodingLife
To view or add a comment, sign in
-
-
Today I Learned: The Surprising History of null in JavaScript Did you know that the concept of null has been in existence for nearly 60 years and is often called a “billion-dollar mistake"? Time ⏰ Where it started In 1965, the computer scientist Sir Tony Hoare introduced the concept of a null reference in ALGOL W to denote the absence of a value. Although useful, it eventually caused an immeasurable amount of bugs, crashes, and security problems — which later motivated Hoare to say: “I call it my billion-dollar mistake.” How it reached JavaScript JavaScript inherited null from Java when it was created by Brendan Eich back in 1995. But it also introduced another value: undefined. Since then developers have had to deal with both: null // absence of intention undefined // not assigned value Fun fact: typeof null === "object" // true In fact, this is a long-standing bug from the earliest JavaScript implementation, kept for compatibility. A good reminder that small design decisions can shape the industry for decades. ⚙️ Modern JavaScript now gives us safer tools to handle missing values: user?.profile // optional chaining value ?? "default" // nullish coalescing Takeaway null was born with good intentions but also taught us a powerful lesson in language design and defensive programming. Understanding its history helps us write cleaner and safer JavaScript. #JavaScript #WebDevelopment #TIL #ProgrammingHistory #SoftwareEngineering #Developers #LearningEveryday # 10000 Coders # Sudheer Velpula
To view or add a comment, sign in
-
-
💡 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗣𝗿𝗼𝘁𝗼𝘁𝘆𝗽𝗮𝗹 𝗜𝗻𝗵𝗲𝗿𝗶𝘁𝗮𝗻𝗰𝗲 — 𝗠𝗮𝗱𝗲 𝗦𝗶𝗺𝗽𝗹𝗲 🧠 When you hear “everything in JavaScript is an object”, you’re actually hearing about the magic of prototypal inheritance. 🔍 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗣𝗿𝗼𝘁𝗼𝘁𝘆𝗽𝗮𝗹 𝗜𝗻𝗵𝗲𝗿𝗶𝘁𝗮𝗻𝗰𝗲? In JavaScript, objects can inherit properties and methods from other objects — not through classes (like Java or C++), but through a special link called a prototype. Every object in JS has an internal reference to another object — its prototype. If a property or method isn’t found on the object itself, JavaScript looks for it in the prototype. This chain continues until it reaches the root object — Object.prototype. That’s called the prototype chain 🔗 🧩 𝗜𝗻 𝘁𝗵𝗲 𝗯𝗲𝗹𝗼𝘄 𝗰𝗼𝗱𝗲, 𝗵𝗲𝗿𝗲’𝘀 𝘄𝗵𝗮𝘁 𝗵𝗮𝗽𝗽𝗲𝗻𝘀: -> user doesn’t have its own greet() method. -> JS checks user.__proto__ (which points to person). -> Finds greet() there and executes it. -> That’s prototypal inheritance in action ✅ 💭 𝗥𝗲𝗮𝗹-𝗟𝗶𝗳𝗲 𝗔𝗻𝗮𝗹𝗼𝗴𝘆: Imagine you don’t own a car 🚗 You borrow your parent’s car — you didn’t “copy” it; you’re just “using it”. That’s exactly how prototypes work — they share behavior, not duplicate it. 🧠 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀 ✅ It makes memory usage efficient. ✅ It’s the foundation of JavaScript’s class syntax (class is just syntactic sugar). ✅ It’s heavily tested in interviews — both theoretically and with small coding challenges. ✨ 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Prototypal inheritance is the core of how JS objects relate to each other. Master this — and you’ll truly understand how JavaScript works behind the scenes 🔥 #JavaScript #WebDevelopment #FrontendDevelopment #Coding #InterviewPreparation #FrontendEngineer #100DaysOfCode #Learning #DevCommunity
To view or add a comment, sign in
-
Explore related topics
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