The JavaScript this keyword — small word, massive confusion. When I first started learning JavaScript, this was easily one of the most confusing concepts. Sometimes it pointed to window, sometimes an object, sometimes undefined. It felt like it had an identity crisis. So I finally sat down and wrote a blog to break it down clearly and practically — no textbook language, no unnecessary theory. In this post, I cover: What this actually is How it changes based on context Common mistakes developers make How to predict what this will refer to before running the code If you’re: Learning JavaScript Preparing for interviews Or revisiting fundamentals this might save you a lot of confusion. 👉 Read here: 🔗 https://lnkd.in/d2dRdH_M If you find it helpful, feel free to share — it might help someone else overcome their this identity crisis too 🙂 #JavaScript #WebDevelopment #Frontend #LearningInPublic #JSFundamentals #Developers
Understanding JavaScript's 'this' Keyword
More Relevant Posts
-
𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 – 𝐏𝐚𝐫𝐭 7: 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐎𝐛𝐣𝐞𝐜𝐭𝐬 Hey everyone! I’m sharing the next part of the JavaScript notes that I prepared while learning JS. I’ve tried to explain everything in the simplest and most beginner-friendly way. 𝗧𝗵𝗶𝘀 𝗽𝗮𝗿𝘁 𝗰𝗼𝘃𝗲𝗿𝘀: 🔹 What is a JavaScript Object? 🔹 Creating JavaScript Objects 🔹 JavaScript Object Properties 🔹 Accessing Object Properties Using Dot Notation Using Bracket Notation 🔹 JavaScript Object Operations Modify object properties Add new properties Delete existing properties 🔹 JavaScript Object Methods 𝗣𝗿𝗲𝘃𝗶𝗼𝘂𝘀 𝗣𝗮𝗿𝘁𝘀: Part 1: JS Fundamentals https://lnkd.in/gZdba3ga Part 2: JS Operators https://lnkd.in/gUYuHXSb Part 3: JS Conditional Statements https://lnkd.in/gWTfwkBr Part 4: Loops https://lnkd.in/gUjuB5eY Part 5: Functions https://lnkd.in/gQZadrza Part 6: Hoisting https://lnkd.in/gewc5fgB Hope this helps Feel free to share with your friends, and please comment your suggestions or doubts. #javascript #webdevelopment #programming #developers #learningbysharing #tech #learninpublic #cse #frontend
To view or add a comment, sign in
-
JavaScript Built-in Methods – Ultimate CheatSheet (PDF) JavaScript learners & developers I’ve compiled a single, easy-to-revise CheatSheet covering the most important JavaScript built-in methods used in real-world development. 📌 What’s included? -- Array, String, Object & Number methods -- Math & Date utilities -- Promises, Async/Await & Fetch API -- DOM, Events & Web APIs -- Browser APIs, Storage, Performance & more This PDF is ideal for: -- Beginners learning JavaScript -- Interview preparation -- Daily quick revision -- Frontend & Full-Stack developers 📄 Save it. Share it. Use it. Because strong fundamentals = better code 👇 Comment “PDF” and I’ll share the link. Mohit Kumar === Mohit Decodes #JavaScript #JavaScriptCheatSheet #WebDevelopment #FrontendDevelopment #FullStackDeveloper #Programming #Coding #LearnJavaScript #DeveloperCommunity #MohitDecodes
To view or add a comment, sign in
-
🚀 JavaScript in 1 page. No fluff. No overwhelm. Most people don’t struggle with JavaScript because it’s hard. They struggle because the basics are scattered everywhere. So I put together a simple, bookmark-worthy JavaScript cheatsheet that brings the most used concepts into one place. Perfect if you’re: • Learning JavaScript • Revising before interviews • Switching between React / Node / frontend work • Tired of Googling the same syntax again and again This cheatsheet helps you: ✅ Recall concepts fast ✅ Write cleaner JS ✅ Build confidence without rereading full docs Think of it as: 👉 “Your quick JS brain refresh” 👉 “From beginner to pro — without the noise” 📌 Save this for later 🔁 Share it with someone learning JavaScript 💬 Comment “JS” if you want more such concise dev notes Following a simple rule lately: Clarity beats complexity. Every time. 👉 Follow Saurav Singh for practical dev learning, cheatsheets, and career clarity. #JavaScript #WebDevelopment #Frontend #LearningInPublic #CodingLife #Developers #InterviewPrep #JS
To view or add a comment, sign in
-
🗓️Day 38 of 100 - Why Does JavaScript Feel So Confusing? 🤯 If you’ve ever felt lost while learning JavaScript, trust me — you’re not alone. At first, JavaScript feels unpredictable: "5" + 1 // "51" "5" - 1 // 4 Same values. Different results. No error. 😅 Then there’s this: "5" == 5 // true "5" === 5 // false Small symbols. Big confusion. But here’s the truth 👇 JavaScript isn’t broken. It’s flexible. JavaScript: • Automatically converts types • Allows dynamic values • Follows hidden execution rules • Handles async work behind the scenes Once I stopped asking ❌ “Why is JavaScript so weird?” and started asking ✅ “What rule is JavaScript following?” Things slowly began to make sense. Feeling confused doesn’t mean you’re bad at coding. It means you’re learning a powerful language. One concept at a time. One bug at a time. It gets better. 💪✨ #JavaScript #WebDevelopment #LearningJourney #100DaysOfCode #Programming
To view or add a comment, sign in
-
-
🧩 Beginner JavaScript Tips: Write Clean & Readable Code - `BOOLEAN`✨ 🤔 Why is this important? Because you will read your own code more times than you write it — and so will your teammates 👀🤝 🌱 When we start coding, our main goal is to make it work. But good developers also make sure the code is easy to understand 💡 Here are a few simple JavaScript habits that really help beginners 🚀 🔹 Boolean names should sound like questions❓ const hasPermissions = (user) => user.role === "ADMIN"; When you read it, the answer feels obvious ✔️ 🚫 Avoid confusing boolean names // ❌ Confusing const hasPermission = false; // ✅ Clear meaning const canUpdate = true; 🧠 Use meaningful prefixes is → state (isLoggedIn) has → ownership (hasCredits) should → expectation (shouldClearCookies) can → ability (canUpdate) ✨ Avoid unnecessary comparisons // ❌ if (isLoggedIn === true){...} // ✅ if (isLoggedIn){...} Less code = fewer bugs 🐞 ⚙️ Use safe default values /*_________Code_Start_______*/ function getDiscount(price, discount) { discount = discount ?? 0.1; // Nullish coalescing (??) -> undefined, null return price - price * discount; } console.log(getDiscount(100, 0.2)); // 0 /*_________Code_End_______*/ Protects your app from null and undefined issues 🛡️ 📌 Small habits like these make your code: ✔️ easier to read ✔️ easier to fix ✔️ easier to scale 💬 Clean code saves time, energy, and mental peace. #JavaScript #BeginnerTips #CleanCode #CodingJourney #Frontend #Learning 🚀
To view or add a comment, sign in
-
So, you're building projects with JavaScript - and that's awesome. But, let's get real, do you really understand how the "this" keyword works? It's tricky. Its value is all about how a function is called, not where it's defined - that's the key. You'll learn a lot: what "this" actually means, how it behaves in different situations, and some common mistakes to avoid. If you're just starting out or looking to refresh your JavaScript skills, this post is for you. It's like having a conversation with a friend - we'll break it down, and I'll share some insights. For instance, think of "this" like a pronoun - its meaning changes depending on the context, just like how "you" can refer to different people in different conversations. And, trust me, understandingthis will make a huge difference in your coding journey - it's a game-changer. Check out this resource for more info: https://lnkd.in/g-tn9CXj #JavaScript #Coding #WebDevelopment
To view or add a comment, sign in
-
Master JavaScript with This One Simple Map! 🚀 Struggling to learn JavaScript? Don't worry—I've got you covered! This easy mindmap breaks it down into super simple steps anyone can follow. What's inside: • Basics: Variables, loops, and functions (start here!). • Web Magic: Play with DOM and fix errors like a pro. • Modern Tricks: Arrow functions, promises, and ES6 goodies. • Pro Level: Security tips, testing, and data structures. • Next Up: Jump into React, Angular, or Vue. Save this for your study sessions or interviews—it's your cheat sheet to JS mastery! 💪 #JavaScript #WebDevelopment #Coding #Programming #Developer #CheatSheet #Learning #Frontend #React #ReactJS #Angular #VueJS #WebDev #FrontendDeveloper #JavaScriptTips #CodingTips #DevCommunity #LearnToCode #JavaScriptRoadmap #BeginnerCoding
To view or add a comment, sign in
-
-
5 Super Useful JavaScript Cheat Sheet If you’re working with JavaScript, this cheat sheet is a must-have 📌 It covers the most commonly used concepts that every developer uses daily: ✅ Array Methods – Easily manipulate, filter, map, and transform data ✅ Date Methods – Work with dates and times efficiently ✅ DOM Methods – Select, create, update, and remove HTML elements ✅ DOM Events – Handle user interactions and make web pages interactive Perfect for beginners learning JavaScript and developers who want a quick refresher. Save it, share it, and keep coding 💻🔥 #JavaScript #WebDevelopment #Frontend #Programming #CodingTips #Developer
To view or add a comment, sign in
-
🚀 MERN Stack Series – Day 10 Today, I learned an important JavaScript concept related to asynchronous programming — Callbacks vs Promises vs Async/Await. 📌 Why Asynchronous JavaScript? JavaScript is single-threaded, but async programming helps handle: API calls File operations Timers Background tasks 🔹 1️⃣ Callbacks A callback is a function passed as an argument to another function and executed later. ✔ Simple to use ❌ Can lead to callback hell ❌ Hard to read and maintain 🔹 2️⃣ Promises A Promise represents a value that may be available now, later, or never. States: Pending Fulfilled Rejected ✔ Better readability ✔ Better error handling than callbacks 🔹 3️⃣ Async / Await async/await is built on top of promises and makes async code look synchronous. ✔ Clean and readable code ✔ Easy error handling using try...catch ✔ Most preferred in modern JavaScript 💡 Best Practice ✔ Avoid callbacks for complex logic ✔ Use Promises or Async/Await ✔ Prefer Async/Await for clean and maintainable code Understanding async JavaScript is essential for working with APIs and real-world applications 🚀 #JavaScript #AsyncAwait #Promises #Callbacks #MERNStack #WebDevelopment #LearningInPublic
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
In short, 'this' is defined for every execution context which includes both global EC and function EC. I you try to access 'this' in the global scope, it will point to window. 1.For a normal function , it returns undefined (in strict mode) or window object (in sloppy mode) 2. Arrow functions don't get 'this' keyword so they take the value from outer scope 3. For event listener functions, this points to the dom element itself