🚀 Today I learned one of the most confusing but powerful JavaScript concepts — Prototype. At first, I used methods like .map(), .filter(), and .push() without thinking where they actually come from. Then I understood the role of Prototype 👇 👉 In JavaScript, objects can inherit properties and methods from another object through the prototype chain. Simple Example: function User(name) { this.name = name; } User.prototype.sayHi = function () { console.log("Hi " + this.name); }; const u1 = new User("Sartaj"); u1.sayHi(); 💡 Why use Prototype? ✔️ Shared methods for all instances ✔️ Better memory efficiency ✔️ Faster and cleaner object creation ✔️ Core concept behind JavaScript classes What I understood: prototype → used to store shared methods __proto__ → link to parent object new keyword connects objects to prototype The more I learn JavaScript fundamentals, the more interesting it becomes. 💻 Which JavaScript concept confused you the most at first? 👇 #JavaScript #WebDevelopment #Prototype #Coding #Frontend #MERNStack #Learning #100DaysOfCode
Understanding JavaScript Prototype and Its Benefits
More Relevant Posts
-
🚀 Day 6/108 – Conditional Statements in JavaScript Continuing my 108-day JavaScript journey — today I learned how to make decisions in code 👇 👉 What are Conditional Statements? They allow us to execute different blocks of code based on conditions. 🧠 Types of Conditional Statements: 🔹 if statement Executes code if a condition is true 🔹 if...else statement Executes one block if true, another if false 🔹 if...else if...else Used to check multiple conditions 🔹 switch statement Used when comparing one value against multiple cases 💻 Example: let age = 18; if (age >= 18) { console.log("You are an adult"); } else { console.log("You are a minor"); } 🧠 Key Insight: Conditions always return either "true" or "false". ⚠️ Quick Note: JavaScript also has truthy and falsy values Falsy values → "false, 0, "", null, undefined, NaN" 🔥 Learning step by step — consistency is everything! How do you usually write conditions — if-else or switch? 👇 #JavaScript #WebDevelopment #CodingJourney #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
-
🚀Day 30 — Scope Chain & Scope Types in JavaScript (Simplified) Understanding scope is one of the most important fundamentals in JavaScript 🚀 --- 🔍 What is Scope? 👉 Scope decides where variables can be accessed in your code In simple words: 👉 “Who can access what?” --- ⚡ Types of Scope 1. Global Scope 👉 Variables declared outside functions or blocks let name = "John"; function greet() { console.log(name); // accessible } --- 2. Function Scope 👉 Variables declared inside a function function test() { let age = 25; console.log(age); } console.log(age); // ❌ Error --- 3. Block Scope 👉 Variables declared with let and const inside {} if (true) { let city = "Delhi"; } console.log(city); // ❌ Error --- 🔗 What is Scope Chain? 👉 If JS can’t find a variable in current scope, it looks in the outer scope, then outer again… until global scope. This is called the Scope Chain --- 🚀 Why it matters ✔ Prevents variable conflicts ✔ Helps understand closures ✔ Improves debugging skills --- 💡 One-line takeaway: 👉 “JavaScript looks upward to find variables — that’s the scope chain.” --- Mastering scope makes closures, hoisting, and debugging much easier. #JavaScript #Scope #ScopeChain #WebDevelopment #Frontend #100DaysOfCode 🚀
To view or add a comment, sign in
-
💡 var, let, const in JavaScript — easy? Not really 😅 If you think you understand them… try predicting these 👇 for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); } Output: 3 3 3 for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); } Output: 0 1 2 🤯 Same code… different output. Why? ⸻ 🔍 The difference: 👉 var is function-scoped • One shared i • All callbacks reference same variable • Final value = 3 👉 let is block-scoped • New i created for each iteration • Each callback gets its own copy 💬 Lesson learned: JavaScript doesn’t just execute code… It follows rules that aren’t always obvious. ⸻ 🚀 Pro Tip: 👉 Prefer let and const over var 👉 Avoid var in modern JavaScript ⸻ #JavaScript #Frontend #WebDevelopment #CodingInterview #JSConcepts #Developers
To view or add a comment, sign in
-
📚 Blog Series Update! Between projects and busy work hours, I spent some time this week working on Part 3 of my Rediscovering JavaScript series, and now I’m happy to share a new weekend read: Variables, Scope, and Memory 🚀 In this blog post, I explore some of the most important JavaScript fundamentals: 🔹 Primitive vs reference values 🔹 Scope and scope chain 🔹 Execution context 🔹 Memory management & garbage collection These topics may sound basic, but they explain many of the “why did this happen?” moments developers face while coding. 🔗 Part 3 Rediscovering JavaScript (Part 3): Variables, Scope, and Memory: https://lnkd.in/ek8CySJc 🔗Friend link: https://lnkd.in/e4ddDhSc ✨ For this journey, I’m using Professional JavaScript for Web Developers by Nicholas C. Zakas as my main guide. ☕ Wishing you a wonderful weekend and an enjoyable read with your coffee! #JavaScript #WebDevelopment #Frontend #Programming #SoftwareEngineering #DevTips #Medium
To view or add a comment, sign in
-
🎇 JavaScript Object Methods Objects are everywhere in JavaScript, but many devs don’t take full advantage of the built-in tools available. Here are some essential object methods to level up your code: 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝗸𝗲𝘆𝘀(𝗼𝗯𝗷): get all the keys 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝘃𝗮𝗹𝘂𝗲𝘀(𝗼𝗯𝗷): get all the values 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝗲𝗻𝘁𝗿𝗶𝗲𝘀(𝗼𝗯𝗷): convert to an array of [key, value] 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝗳𝗿𝗼𝗺𝗘𝗻𝘁𝗿𝗶𝗲𝘀(): convert back from entries to object 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝗵𝗮𝘀𝗢𝘄𝗻(): check for a property (modern & safer) 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝗮𝘀𝘀𝗶𝗴𝗻(): shallow merge objects 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝗳𝗿𝗲𝗲𝘇𝗲(): make an object immutable 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝘀𝗲𝗮𝗹(): prevent adding/removing properties 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝗱𝗲𝗳𝗶𝗻𝗲𝗣𝗿𝗼𝗽𝗲𝗿𝘁𝘆(): fine-grained control over properties 🔹 𝗢𝗯𝗷𝗲𝗰𝘁.𝗴𝗲𝘁𝗣𝗿𝗼𝘁𝗼𝘁𝘆𝗽𝗲𝗢𝗳(): peek under the hood Save & share with your team! Download Our Free Full-Stack Developer Starter Kit ➡️ https://buff.ly/JbI0Qof --- If you found this guide helpful, follow TheDevSpace | Dev Roadmap, w3schools.com, and JavaScript Mastery for more tips, tutorials, and cheat sheets on web development. Let's stay connected! 🚀 #React #JavaScript #CheatSheet #WebDevelopment
To view or add a comment, sign in
-
-
🚨 Ever wondered why your JavaScript code doesn’t freeze even when tasks take time? Here’s the secret: the event loop — the silent hero behind JavaScript’s non-blocking magic. JavaScript is single-threaded, but thanks to the event loop, it can handle multiple operations like a pro. Here’s the simplified flow: ➡️ The Call Stack executes functions (one at a time, LIFO) ➡️ Web APIs handle async tasks like timers, fetch, and DOM events ➡️ Completed tasks move to the Callback Queue (FIFO) ➡️ The Event Loop constantly checks and pushes callbacks back to the stack when it’s free 💡 Result? Smooth UI, responsive apps, and efficient async behavior — all without true multithreading. Understanding this isn’t just theory — it’s the difference between writing code that works and code that scales. 🔥 If you’re working with async JavaScript (Promises, async/await, APIs), mastering the event loop is a game-changer. #JavaScript #WebDevelopment #AsyncProgramming #EventLoop #Frontend #CodingTips
To view or add a comment, sign in
-
-
💻 JavaScript Array Methods – Hands-on Practice Completed Worked on some fundamental Array methods in JavaScript and practiced how they actually behave 👇 ✔️ Used push() and pop() to add/remove elements from the end ✔️ Used unshift() and shift() to work with elements at the beginning ✔️ Explored length to track array size ✔️ Understood the difference between slice() and splice() through practice 💡 Key takeaway: slice() does not modify the original array, while splice() directly changes it — this difference is really important while working with data. Practicing these basics is helping me build a strong foundation in JavaScript 🚀 #JavaScript #WebDevelopment #Frontend #CodingJourney #LearningByDoing
To view or add a comment, sign in
-
-
⚡ Day 7 — JavaScript Event Loop (Explained Simply) Ever wondered how JavaScript handles async tasks while being single-threaded? 🤔 That’s where the Event Loop comes in. --- 🧠 What is the Event Loop? 👉 The Event Loop manages execution of code, async tasks, and callbacks. --- 🔄 How it works: 1. Call Stack → Executes synchronous code 2. Web APIs → Handle async tasks (setTimeout, fetch, etc.) 3. Callback Queue / Microtask Queue → Stores callbacks 4. Event Loop → Moves tasks to the stack when it’s empty --- 🔍 Example: console.log("Start"); setTimeout(() => { console.log("Timeout"); }, 0); Promise.resolve().then(() => { console.log("Promise"); }); console.log("End"); --- 📌 Output: Start End Promise Timeout --- 🧠 Why? 👉 Microtasks (Promises) run before macrotasks (setTimeout) --- 🔥 One-line takeaway: 👉 “Event Loop decides what runs next in async JavaScript.” --- If you're learning async JS, understanding this will change how you debug forever. #JavaScript #EventLoop #WebDevelopment #Frontend #100DaysOfCode 🚀
To view or add a comment, sign in
-
🚀 Day 979 of #1000DaysOfCode ✨ 4 Useful Number Functions in JavaScript (With Cool Examples) JavaScript provides many built-in number utilities — but most developers only use a few of them. In today’s post, I’ve shared 4 super useful number functions in JavaScript along with some cool and practical examples for each. These functions can help you handle number validation, formatting, and edge cases more effectively in real-world applications. Small utilities like these might look simple, but they can save you time and help you write cleaner and more reliable logic. Once you start using them properly, you’ll notice how often they come in handy while working with data. If you work with numbers, calculations, or user inputs in JavaScript, these functions are definitely worth knowing. 👇 Which JavaScript number function do you use the most in your projects? #Day979 #learningoftheday #1000daysofcodingchallenge #FrontendDevelopment #WebDevelopment #JavaScript #React #CodingCommunity #JSDevelopers
To view or add a comment, sign in
-
🚀 Day 7 — Understanding JavaScript Objects & Prototypes Continuing my journey of strengthening core JavaScript fundamentals, today I explored one of the most important building blocks — Objects & Prototypes 👇 At first, objects feel simple… but when you dive into prototypes, you truly understand how JavaScript works behind the scenes. 🔹 Covered topics: - What are JavaScript Objects? - Key-Value Pairs & Properties - Dot vs Bracket Notation - Add / Modify / Delete Properties - Object Methods - "this" inside objects (quick revision 🔁) - Constructor Functions - What happens when we use "new" - Why Prototype is needed (memory optimization 🔥) - Prototype & Shared Methods - Prototype Chain (🔥 very important) - Getter & Setter 💡 Key Learning: JavaScript is not class-based — it’s prototype-based. Objects can share properties and methods using prototypes, which makes code more efficient and scalable. 👉 Always remember: - JS first looks inside the object - If not found → it checks the prototype (This is called the Prototype Chain) Understanding this concept is a game changer for interviews and helps in writing better, optimized code. 📌 Day 7 of consistent preparation — going deeper into JavaScript fundamentals 🔥 #JavaScript #WebDevelopment #FullStackDeveloper #CodingJourney #MERNStack #InterviewPreparation #Frontend #Backend #LearnInPublic #Developers #Consistency #100DaysOfCode #LinkedIn #Connections
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