Most JavaScript developers get confused with this 🤯 But once you understand how a function is called, everything becomes clear. ⚡ What is this in JavaScript? this is a keyword that refers to the object that is executing the current function. But the tricky part is… 👉 this changes depending on how the function is called. Example: const user = { name: "John", sayHi: function() { console.log("Hi, " + this.name); } }; user.sayHi(); // Hi, John Here this refers to the user object. 💡 Key things to remember ✔ this depends on how the function is called ✔ Inside an object method → this refers to that object ✔ Arrow functions → use the parent scope this ✔ call() / apply() can manually change this 📌 Pro Tip: Always check how the function is called, not where it is written. If you're learning JavaScript, mastering this will save you from many debugging headaches later. Follow for more JavaScript concepts explained simply. 🚀 #javascript #webdevelopment #frontenddevelopment #coding #programming #js #learnjavascript #softwaredeveloper #100daysofcode #developer
Understanding JavaScript's 'this' keyword
More Relevant Posts
-
💡 Understanding Scope in JavaScript One of the most important concepts in JavaScript is Scope. Scope defines where variables can be accessed in your code. There are three main types of scope in JavaScript: 🔹 Global Scope Variables declared outside any function are accessible anywhere in the program. let name = "Muneeb"; function showName() { console.log(name); } showName(); // Accessible because it's global 🔹 Function Scope Variables declared inside a function can only be used inside that function. function greet() { let message = "Hello"; console.log(message); } greet(); // console.log(message); ❌ Error 🔹 Block Scope Variables declared with "let" and "const" inside "{ }" are only accessible within that block. if (true) { let age = 25; console.log(age); } // console.log(age); ❌ Error 📌 Understanding scope helps developers write cleaner code and avoid bugs related to variable access. Mastering these fundamentals makes JavaScript much easier to understand and improves problem-solving skills. #JavaScript #WebDevelopment #FrontendDeveloper #Coding #LearnToCode
To view or add a comment, sign in
-
JavaScript fun facts that sound fake but are actually real: - "typeof null" → ""object"" (this is a bug from early JS that was never fixed) --- - "[] + []" → """" (empty string) --- - "[] + {}" → ""[object Object]"" --- - "{} + []" → "0" (yes… seriously) --- - "NaN === NaN" → "false" (the only value not equal to itself) --- - "0.1 + 0.2 !== 0.3" (floating point precision issue) --- - Functions are objects in JavaScript → you can add properties to them --- - JavaScript is single-threaded → but still handles async like a pro using event loop --- - "setTimeout(fn, 0)" does NOT run immediately → it runs after the call stack is empty --- If JavaScript ever feels weird, it’s not you. It’s JavaScript. Still learning, still questioning. #JavaScript #WebDevelopment #FrontendDevelopment #Programming #Developers #CodingJourney #TechFacts #BuildInPublic
To view or add a comment, sign in
-
-
The reduce() function is one of the most powerful — and most confusing — concepts in JavaScript. But once you understand it, it becomes a game changer. In this video, I explain reduce in a simple way: • How reduce converts an array into a single value • Role of the accumulator • How values are combined step-by-step • Examples using sum and multiplication • Real-world usage in applications Example: [1,2,3,4] → 10 reduce() is widely used for: • Data transformation • Aggregation logic • Complex frontend operations Understanding reduce is essential for writing efficient JavaScript. 📺 Watch the full video: https://lnkd.in/gJpCMZKD 🎓 Learn JavaScript & React with real-world projects: 👉 https://lnkd.in/gpc2mqcf 💬 Comment LINK and I’ll share the complete JavaScript roadmap. #JavaScript #ReactJS #FrontendEngineering #WebDevelopment #SoftwareEngineering #Programming #DeveloperEducation
Why Developers Struggle with reduce()
To view or add a comment, sign in
-
🚀 JavaScript Fundamentals Series — Part 4 Functions are where JavaScript becomes powerful and reusable. Instead of repeating code, functions let you create reusable logic blocks. In this guide you'll learn: • What functions actually are • Parameters vs arguments • Return values • Function declarations vs expressions • How functions organize your code Functions are the foundation of almost everything in JavaScript. Full guide 👇 https://lnkd.in/dtgFaW2r #javascript #webdevelopment #coding
To view or add a comment, sign in
-
Most developers learn JavaScript… but struggle when it comes to arrays in real projects. And the truth is — Arrays are used everywhere. So I created a JavaScript Array CheatSheet that makes everything simple and practical. Inside this guide: ⚡ Add elements → push() / unshift() ⚡ Remove elements → pop() / shift() ⚡ Check existence → includes() ⚡ Find index → indexOf() ⚡ Iterate arrays → forEach() / map() ⚡ Find elements → find() Each concept is explained with: ✔ Clean code examples ✔ Real outputs ✔ Easy-to-understand logic Perfect for: ✅ Beginners learning JavaScript ✅ Frontend developers ✅ Interview preparation ✅ Quick revision before coding 💡 If you master arrays, you unlock 80% of JavaScript logic building. 📌 Save this post — you’ll need it again. 💬 Comment “JS” and I’ll share the full cheat sheet. Follow for more JavaScript tips, roadmaps, and developer content. #JavaScript #FrontendDevelopment #WebDevelopment #JS #CodingTips #LearnJavaScript #Programming #Developers #SoftwareEngineering #CodingLife #DeveloperCommunity #SurajSingh
To view or add a comment, sign in
-
🚀 JavaScript String Cheatsheet — Save This! If you're working with JavaScript, mastering string methods is a game changer. From basic manipulation to advanced searching — everything in one place 👇 💡 Here’s what you’ll learn from this cheatsheet: ✔️ String declaration & template literals ✔️ Search methods (indexOf, charAt, etc.) ✔️ Powerful string functions (slice, split, replace) ✔️ Checking & comparing strings ✔️ Padding, trimming & formatting 👉 Whether you're a junior developer or brushing up your skills, this is a must-save resource! 🔥 Pro Tip: Practice these methods daily — they show up everywhere in real projects. 💬 Which method do you use the most? Let me know in the comments! 📌 Don’t forget to: 👍 Like 🔁 Share 💾 Save for later #JavaScript #WebDevelopment #Programming #Developer #CodingLife #Frontend #SoftwareEngineering #LearnToCode #TechTips #Developers #CodingTips #JS #100DaysOfCode #CareerGrowth #DevCommunity
To view or add a comment, sign in
-
-
New Blog Published: Mastering call(), apply(), and bind() in JavaScript Ever wondered why the this keyword in JavaScript sometimes behaves unexpectedly? Many developers memorize call(), apply(), and bind() but don’t fully understand why these methods exist or when to actually use them. In real-world JavaScript applications, controlling this is important for writing reusable functions, borrowing methods between objects, and fixing context issues in callbacks. In this blog, I break down: • Why JavaScript needed call(), apply(), and bind() • The core difference between these three methods • When to use each one in real scenarios • A simple restaurant chef analogy to make the concept intuitive • Practical code examples to make everything clear Written in a simple and practical way for developers who want to truly understand how this works in JavaScript. 🔗 Read here: https://lnkd.in/g6-xTkcS Hitesh Choudhary Piyush Garg Akash Kadlag Jay Kadlag Anirudh Sir #JavaScript #SoftwareDevelopment #Programming #WebDev #ChaiCode
To view or add a comment, sign in
-
🚀 JavaScript Concepts Series – Day 3 / 30 👀 Let's Revise the Basics🧐 Understanding the difference between var, let, and const is a fundamental concept in JavaScript. Choosing the right variable declaration helps prevent bugs and makes your code more predictable. 🔹 var Function scoped Can be redeclared Can be reassigned Hoisted (initialized with undefined) 🔹 let Block scoped Cannot be redeclared in the same scope Can be reassigned Hoisted but stays in Temporal Dead Zone (TDZ) until initialized 🔹 const Block scoped Cannot be redeclared Cannot be reassigned Must be initialized during declaration 💡 Key Insight var → Old way of declaring variables (function scoped) let → Use when the value may change const → Use when the value should not change Using let and const helps write safer and more maintainable JavaScript code. More JavaScript concepts coming soon. 🚀 #javascript #js #webdevelopment #frontenddeveloper #coding #programming #softwaredeveloper #developers #learnjavascript #javascriptdeveloper #codinglife #devcommunity #webdev #reactjs #mernstack #codingjourney #codeeveryday #techlearning #developerlife #100daysofcode
To view or add a comment, sign in
-
-
🚀 Day 22 – Understanding the this Keyword in JavaScript If there’s one concept that confuses almost every JavaScript developer at some point… it’s this 😅 But once you get it right, everything starts to make sense 🔥 🧠 The Truth About this 👉 this doesn’t refer to where the function is written 👉 It refers to how the function is called That’s the game changer. ⚡ What I Learned Today ✔️ In objects → this refers to the object ✔️ In regular functions → this is global (or undefined in strict mode) ✔️ In arrow functions → no own this (inherits from parent) ✔️ In event listeners → this is the element 👨💻 Angular Dev Tip If you’ve ever lost this inside setTimeout or callbacks… you’re not alone 😄 👉 Arrow functions are your best friend here: They preserve the component context ✅ 💡 Why This Matters Understanding this helps you: Write cleaner, bug-free code Avoid unexpected behavior Master advanced JS concepts #JavaScript #Angular #FrontendDevelopment #WebDevelopment #100DaysOfCode #LearnInPublic
To view or add a comment, sign in
-
-
🚀 JavaScript Concepts Series – Day 6 / 30 📌 Closures in JavaScript 👀 Let’s Revise the Basics 🧐 A closure is when a function remembers variables from its outer scope even after the outer function has finished execution. 🔹 Key Points • Inner function can access outer variables • Data persists even after function execution • Useful for data privacy and state management 🔹 Example function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 💡 Key Insight Closure → Function + its lexical scope Remembers → Outer variables after execution Closures are widely used in callbacks, event handlers, and React hooks. More JavaScript concepts coming soon. 🚀 #javascript #js #webdevelopment #frontenddeveloper #coding #programming #developers #softwaredeveloper #learnjavascript #javascriptdeveloper #codinglife #devcommunity #webdev #reactjs #mernstack #codingjourney #codeeveryday #developerlife #100daysofcode #techlearning
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