🚀 𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 𝗣𝗿𝗼𝘅𝘆 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 ⤵️ Recently, I was studying about Proxy in JavaScript and here’s what I’ve learned 👇 ⇾ What is 𝗽𝗿𝗼𝘅𝘆? A Proxy lets you wrap an object and control what happens when someone reads, writes, or modifies its properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs, and so on. You can create a Proxy with two parameters: • 𝙩𝙖𝙧𝙜𝙚𝙩: the original object which you want to proxy. • 𝙝𝙖𝙣𝙙𝙡𝙚𝙧: an object that defines which operations will be intercepted and how to redefine intercepted operations. ⇾ 𝙜𝙚𝙩 - when a property is read Controls what happens when someone tries to access a property. ⇾ 𝙨𝙚𝙩 - when a property is modified Controls what happens when someone tries to assign a property. #JavaScript #WebDevelopment #FrontendDevelopment #CodingJourney #LearnInPublic
Understanding Proxy in JavaScript: A Beginner's Guide
More Relevant Posts
-
🧩 Undefined vs Null 🤔 ✨ When there’s no existence, it’s Undefined, whereas emptiness exists by choice, it’s Null. 🔹 undefined → When a variable is declared but not assigned by the user, JavaScript itself assigns the value undefined by default. let a; console.log(a); // undefined 🧠 It means: “No value exists yet — JavaScript couldn’t find one.” 🔹 null → When a variable is explicitly assigned by the user to represent emptiness, it holds the value null. let b = null; console.log(b); // null 💡 It means: “The developer intentionally set this to nothing.” ⚙️ Type check curiosity typeof null; // "object" ❗ (a known JavaScript bug) typeof undefined; // "undefined" 🚫 Falsy values Both are falsy during condition checks 👇 if (!undefined && !null) console.log('Falsy values!'); 🎯 In short: 🟠 undefined → Not assigned by the user → JavaScript assigns it automatically. 🟣 null → Explicitly assigned by the user → JavaScript doesn’t assign it. 🔖 Hashtags #JavaScript #WebDevelopment #Frontend #CodingTips #LearnToCode #JSBasics #WebDevCommunity #JavaScriptTips #CodeNewbie #DeveloperInsights
To view or add a comment, sign in
-
🚀 JavaScript Trick of the Day! const a = { valueOf: () => 2 * 1 }; console.log(2 + a); // What’s the output? 💡 Answer: 4 Why? When using +, JavaScript tries to convert objects to a primitive. Since the object has a custom valueOf(), JS uses that → returns 2. So: 2 + 2 = 4. 🧠 A reminder that JavaScript type coercion can be surprising — but powerful when understood! #JavaScript #WebDevelopment #CodingTips #100DaysOfCode #JSInterviewPrep
To view or add a comment, sign in
-
I ran this JavaScript snippet, and the output completely surprised me 😳. Day 10: How JavaScript actually handles a async operations ⚙️. 🧠 Logic: 🔹 JS execution always starts with synchronous code -> so "start", "First" & "end" log first. 🔹 Inside the loop, setTimeout is added to macrotask queue (it will run later). 🔹 Promise.then() is added to microtask queue (these will run right after sync code), cause of high priority then macrotask queue. 🔹 Inside asyncFn(), when execution hits await it pauses that function exec & waits for promise to get resolve. 🔹 In the mean time, event Loop continue with promise callback in microTask, one it's completed, the promise get resolved in asyncFn() & then it prints ("Second") to console. 🔹 And the last, the setTimeout callback in macroTask queue gets executed. So: ✅ Promise run first (microTasks). ⏱️ SetTimeout run after (macroTasks). That's why promise 0, promise 1, promise 2, and Second appear before all TimeOut logs. #Javascript #InterviewPrep #100DaysOfCode #CodingChallenge #JavaScript #CodingInterview #JSChallenges
To view or add a comment, sign in
-
-
🚀 Day 19 of 30 Days of JavaScript – LeetCode Problem: 1207. Unique Number of Occurrences Today’s challenge was all about checking whether the number of occurrences of each value in an array is unique. ✅ My Approach 1️⃣ Count occurrences I used a for...of loop to count how many times each element appears in the array. 2️⃣ Store frequency results This gives me an object holding the occurrence count of every unique item. 3️⃣ Convert to a Set I extracted the values and converted them into a Set using new Set(), since a set automatically removes duplicates. 4️⃣ Compare values Arrays and sets can’t be directly compared, so I converted both to strings using JSON.stringify() to compare their datatype + values. 5️⃣ Return result If both match, I return true; otherwise, false. #JavaScript #LeetCode #30DaysOfCode #codingjourney #developerlife
To view or add a comment, sign in
-
-
How TypeScript ‘just knows’ the types from a plain JavaScript library? That magic comes from .𝗱.𝘁𝘀 𝗳𝗶𝗹𝗲𝘀 - Type Declaration files. They don’t contain any logic. They simply describe what a library exposes - the functions, parameters, return types, and more. So when you import something like "lodash", TypeScript instantly provides IntelliSense and type safety. All thanks to @types/lodash, which ships those .d.ts definitions. Without them? No autocomplete. No type hints. Just... guesswork. 😅 Think of .d.ts files as 𝗧𝘆𝗽𝗲𝗦𝗰𝗿𝗶𝗽𝘁’𝘀 𝗱𝗶𝗰𝘁𝗶𝗼𝗻𝗮𝗿𝘆 for JavaScript libraries — helping your editor speak fluent types even when the code doesn’t. Do you remember the first time you realized this? Or ever had to write one yourself? #TypeScript #JavaScript #WebDevelopment #Frontend #DevTips #CodeSmarter #IntelliSense #DefinitelyTyped #DeveloperExperience
To view or add a comment, sign in
-
-
🗓️ Day 12 of JavaScript LeetCode Challenge Problem: 2619. Array Prototype Last Approach: In this problem, I enhanced the Array prototype to include a custom method last() that returns the last element of an array. If the array is empty, it returns -1. I used the this keyword in JavaScript, which refers to the current object on which the function is being called. In global scope, this refers to the window object. Inside a function or method, the value of this depends on how the function is called. Here, since the last() method is called on an array, this refers to that specific array instance. Using this reference, we can easily access its length and return the last element.
To view or add a comment, sign in
-
-
When I first learned JavaScript, hoisting felt confusing — but it’s actually simple. Hoisting means: JavaScript moves variable and function declarations to the top of their scope before executing the code. So you can use a variable or function before it's declared — but the results depend on how it’s declared. 🧠 Why does this happen? var is hoisted and initialized as undefined → no error. let and const are hoisted but stay in the Temporal Dead Zone (TDZ) → error if accessed before initialization. Function declarations are fully hoisted → you can call them before writing them. 💡 In short: ✔ var → hoisted, value = undefined ✔ function → fully hoisted ❌ let & const → hoisted but not usable (TDZ) #JavaScript #Hoisting #WebDevelopment #Frontend #LearnInPublic #MERNStack #30DaysOfCode
To view or add a comment, sign in
-
-
🚨 JavaScript is sneakier than you think… Why do these all return true? '5' == 5 [] == '' [1] == true [] == 0 [null] == 0 Answer: type coercion. 😯 When == is used, JavaScript doesn’t just compare, it actually tries to convert values to compatible types: Primitives → coerced to match Objects/arrays → converted to primitives (valueOf() || toString()) Note: Once you understand this, “weird JavaScript bugs” stop being surprises, they become predictable. 🙂
To view or add a comment, sign in
-
🧠 Understanding the `this` Keyword in JavaScript One of the most confusing yet powerful concepts in JavaScript — the `this` keyword — is something every developer must deeply understand. In today’s post, I’ve covered: ✅ What `this` actually refers to in different contexts ✅ How it behaves inside functions, objects, and classes ✅ Common mistakes developers make ✅ Practical examples to master its behavior If you’ve ever found `this` acting unexpectedly in your code, this post will clear it all up once and for all. 💬 What’s the most confusing part of `this` for you? Share your thoughts in the comments 👇 #JavaScript #FrontendDevelopment #WebDevelopment #CleanCode #CodingCommunity #JSBasics #ProgrammingTips
To view or add a comment, sign in
-
🧠 Understanding the `this` Keyword in JavaScript One of the most confusing yet powerful concepts in JavaScript — the `this` keyword — is something every developer must deeply understand. In today’s post, I’ve covered: ✅ What `this` actually refers to in different contexts ✅ How it behaves inside functions, objects, and classes ✅ Common mistakes developers make ✅ Practical examples to master its behavior If you’ve ever found `this` acting unexpectedly in your code, this post will clear it all up once and for all. 💬 What’s the most confusing part of `this` for you? Share your thoughts in the comments 👇 #JavaScript #FrontendDevelopment #WebDevelopment #CleanCode #CodingCommunity #JSBasics #ProgrammingTips
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