📌 call, apply, bind in JavaScript These methods are used to control the value of this inside a function. 🔹 call() Calls a function immediately and sets this. Use case: Borrow a function from another object. 🔹 apply() Same as call, but arguments are passed as an array. Use case: Useful when arguments are already in an array. 🔹 bind() Returns a new function with this permanently bound. Use case: Used in callbacks, event handlers, and async code. Thanks to - aka Anshu Pandey #JavaScript #WebDevelopment #Frontend #JSConcepts #Developers
JavaScript this binding methods: call, apply, bind
More Relevant Posts
-
❓ Ever wondered why JavaScript sorts numbers “wrong”? Try this: [1, 10, 2].sort() Output: [1, 10, 2] Wait… why not [1, 2, 10]? 🤯 🧠 The reason: By default, JavaScript’s .sort() converts numbers into strings and sorts alphabetically. So it compares: "1", "10", "2" And "10" comes before "2". Sneaky default behavior 👀 ✅ The fix: arr.sort((a, b) => a - b) Now JS knows it’s numeric sorting. Tiny detail. Big difference. Sometimes bugs aren’t errors — they’re misunderstood defaults 😌 #JavaScript #WebDevelopment #CodingJourney #Frontend #Developers
To view or add a comment, sign in
-
Simple JavaScript problem. Clean solution. Find unique characters in a string 👇 Most developers write extra logic for simple problems. The language already gives you tools. You just need to use them properly. How would you solve this WITHOUT using Set? #JavaScript #WebDevelopment #CodingTips #Frontend #Developers
To view or add a comment, sign in
-
-
Built a Password Generator using React while learning React Hooks in depth. Worked with useState, useEffect, useCallback, and useRef to understand state management, DOM access, and performance optimization in a practical way. #ReactJS #WebDevelopment #Frontend #LearningInPublic #JavaScript
To view or add a comment, sign in
-
Simple JavaScript challenge 🧑💻 What will be the output of this code? for ( var i = 0; i < 3; i++ ) { setTimeout( () => { console.log( i ); }, 0 ); } What's your answer? And why? #JavaScript #WebDevelopment #Frontend
To view or add a comment, sign in
-
-
𝗥𝗲𝗮𝗰𝘁 𝗸𝗲𝘆𝘀: 𝗶𝗻𝗱𝗲𝘅 𝘄𝗼𝗿𝗸𝘀… 𝘂𝗻𝘁𝗶𝗹 𝗶𝘁 𝗱𝗼𝗲𝘀𝗻’𝘁. A lot of weird UI bugs in production come from this: ❌ Problem: ``` items.map((item, index) => <Row key={index} />) ``` React doesn’t track list items by “data”. It tracks component identity using keys and reuses DOM/state based on that reference. So when you: • sort • filter • insert • delete the index changes, and React reuses the wrong DOM/state. Result: • inputs swap values • checkbox state mismatches • selected item jumps • animations glitch ✅ Fix: ``` items.map((item) => <Row key={item.id} />) ``` Rule: If the order can change → keys must be stable. Have you ever debugged this bug and later found it was the key? 👀 #ReactJS #Frontend #JavaScript #WebDev #Nextjs
To view or add a comment, sign in
-
-
🚀 𝗧𝗿𝗲𝗲 𝗦𝗵𝗮𝗸𝗶𝗻𝗴 𝗶𝗻 𝗥𝗲𝗮𝗰𝘁 / 𝗝𝗦 🌳✨ Tree Shaking is a bundling technique that removes unused code from your final build. ✅ Smaller bundle size ✅ Faster load time ✅ Better performance 💡 Works best with 𝗘𝗦𝟲 𝗶𝗺𝗽𝗼𝗿𝘁𝘀/𝗲𝘅𝗽𝗼𝗿𝘁𝘀. Example: 𝘪𝘮𝘱𝘰𝘳𝘵 { 𝘥𝘦𝘣𝘰𝘶𝘯𝘤𝘦 } 𝘧𝘳𝘰𝘮 "𝘭𝘰𝘥𝘢𝘴𝘩"; #ReactJS #JavaScript #Frontend #Performance #WebDevelopment
To view or add a comment, sign in
-
-
🤯 This JavaScript snippet will catch you off guard... const obj = { value: 10, double() { return this.value * 2; } }; const { double } = obj; console.log(double()); // What do you think prints? 💭 Most developers say 20. The real answer? NaN. Here's why 👇 When you destructure double from obj, it loses its this binding. Called as a plain function, this no longer points to obj — it points to undefined (strict mode) or the global object (non-strict), where value doesn't exist. So this.value becomes undefined, and undefined * 2 = NaN. ✅ Let me know how will you fix it before the console. The rule to remember: A method is only bound to its object when called AS a method (obj.double()). The moment you detach it, this is gone. This trips up even experienced developers. How many of you got it right? 👇 #JavaScript #WebDev #Frontend #JSInterviewTips #CodingTips #InterviewExperience
To view or add a comment, sign in
-
Most developers use these hooks interchangeably… That’s a mistake. Understanding this difference can prevent flickers, layout bugs, and performance issues. Save this for later For more information contact : https://lnkd.in/gNan5xMQ #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #ReactHooks #SoftwareDevelopment #UIUX #LinkedInLearning #TechTips #Developers #CrystalZenTechnology
To view or add a comment, sign in
-
null vs undefined in JavaScript — Same but Different One of the most confusing topics in JavaScript is the difference between null and undefined. Here’s the simple breakdown: • undefined → A variable is declared but not assigned. • null → An intentional empty value assigned by the developer. Key difference: null == undefined // true null === undefined // false Best Practice: ✔ Use null when you intentionally want no value ✔ Let undefined be the default state ✔ Prefer strict equality (===) Understanding this small difference can prevent many hidden bugs in real-world projects. #JavaScript #WebDevelopment #Coding #Frontend #Developers
To view or add a comment, sign in
-
-
Still using JavaScript arrays the same way you always have? Modern array methods can make everyday tasks simpler and your code easier to read. This covers practical tips to help you: • Replace values cleanly • Reset arrays without workarounds • Convert arrays into objects • Sum values efficiently • Find the last occurrence of elements Small improvements like these add up quickly in real projects. Which array method do you rely on most? [Check the Link in the Comment! 🔗] #JavaScript #WebDevelopment #Frontend #CodingTips #ArrayMethods #DevTips #Syncfusion
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