🚀 Day 85 of My #100DaysOfCode Challenge One of the most confusing things in JavaScript is the "this" keyword. Many developers think "this" always refers to the current object… but that’s not always true. In JavaScript, the value of "this" depends on how a function is called, not where it is written. Let’s see a quick example 👇 const user = { name: "Tejal", greet() { console.log(this.name); } }; user.greet(); ✅ Output Tejal Here "this" refers to the object that called the function. But look at this 👇 const user = { name: "Tejal", greet: () => { console.log(this.name); } }; user.greet(); ❌ Output undefined Why? Because arrow functions don’t create their own "this". They inherit "this" from the surrounding scope. ⚡ Simple rule to remember • Regular functions → "this" depends on how the function is called • Arrow functions → "this" comes from the outer scope Understanding this small concept can save hours of debugging in real projects. JavaScript keeps reminding me that small details often make the biggest difference. #Day85 #100DaysOfCode #JavaScript #CodingJourney #WebDevelopment #LearningInPublic
Understanding JavaScript's 'this' Keyword
More Relevant Posts
-
🧠 Ever wondered how JavaScript keeps track of which function is running? JavaScript uses something called the Call Stack. Think of it like a stack of tasks where functions are added and removed as they execute. 🔹 How the Call Stack Works JavaScript follows a Last In, First Out (LIFO) rule. That means: The last function added to the stack is the first one to finish. Example function first() { second(); } function second() { third(); } function third() { console.log("Hello from third function"); } first(); What happens in the Call Stack 1️⃣ first() is pushed to the stack 2️⃣ second() is called → pushed to the stack 3️⃣ third() is called → pushed to the stack 4️⃣ third() finishes → removed from stack 5️⃣ second() finishes → removed 6️⃣ first() finishes → removed 🔹 Visualising the Stack Call Stack at peak: - third() - second() - first() - Global() Then it unwinds back to the Global Execution Context. 💡 Why This Matters Understanding the call stack helps you understand: - Execution order - Stack overflow errors - Debugging JavaScript - Async behaviour It’s one of the core mechanics of the JavaScript engine. Next post: The Event Loop 🚀 #JavaScript #CallStack #Frontend #WebDevelopment #LearnJS #Programming #LearningInPublic
To view or add a comment, sign in
-
-
💻 JavaScript Practice: Merging Two Arrays Using a While Loop Today I practiced an important JavaScript concept — merging two arrays using a while loop. It’s a great exercise to improve logical thinking and understand how loops and indexes work together. Instead of using built-in methods like concat() or the spread operator, I tried doing it manually with a while loop. This helps in understanding how data moves step by step inside arrays. Key Idea: Start with two arrays. Use a while loop to iterate through them. Push elements into a new array until all elements are merged. Example: let arr1 = [1, 2, 3]; let arr2 = [4, 5, 6];then let result = [1,2,3,4,5,6] Practicing these small problems helps build a stronger foundation in JavaScript logic and problem-solving. 🚀 #JavaScript #DSA #WebDevelopment #CodingPractice #FrontendDevelopment 😊
To view or add a comment, sign in
-
Javascript: Undefined vs null Ever seen undefined and null in JavaScript and felt confused? 🤔 You’re not alone. Many beginners mix them up. But the difference is actually very simple. Here’s the easy way to understand it: • undefined → A variable is declared but no value is assigned yet let name; console.log(name); // undefined • null → A developer intentionally sets an empty value let user = null; • undefined is automatic – JavaScript gives it by default. • null is intentional – The developer sets it manually. • Both mean “no value”, but the reason is different. Simple rule to remember: 👉 undefined = not assigned yet 👉 null = intentionally empty Understanding this small concept can help you avoid many bugs in JavaScript. #JavaScript #WebDevelopment #FrontendDevelopment #ProgrammingTips #LearnJavaScript #CodingForBeginners #SoftwareEngineering #TechEducation #JavaScriptDeveloper #DevCommunity
To view or add a comment, sign in
-
-
🚨 JavaScript Challenge — 90% Get This Wrong No long questions. Just pure JavaScript. 👇 Answer before checking comments. 🧠 𝟭. 𝗪𝗵𝗮𝘁 𝘄𝗶𝗹𝗹 𝘁𝗵𝗶𝘀 𝗹𝗼𝗴? console.log(0.1 + 0.2 === 0.3); Yes or No? And why? ⚡ 𝟮. 𝗣𝗿𝗲𝗱𝗶𝗰𝘁 𝘁𝗵𝗲 𝗼𝘂𝘁𝗽𝘂𝘁 console.log("5" - 3); console.log("5" + 3); Same inputs. Different results. Explain. 🔥 𝟯. 𝗧𝗵𝗶𝘀 𝗼𝗻𝗲 𝗯𝗿𝗲𝗮𝗸𝘀 𝗯𝗿𝗮𝗶𝗻𝘀 console.log([] == ![]); True or False? (No guessing — explain it.) 🧩 𝟰. 𝗢𝘂𝘁𝗽𝘂𝘁? const obj = { a: 1 }; Object.freeze(obj); obj.a = 2; console.log(obj.a); Does it change or not? 🚀 𝟱. 𝗙𝗶𝗻𝗮𝗹 𝘁𝗿𝗮𝗽 console.log(typeof undefined); console.log(typeof null); Why is JavaScript like this? 😄 💬 Be honest — how many did you get 100% correct without Googling? Drop your answers below 👇 Let’s see who actually understands JS fundamentals. I’ll post detailed explanations in the next post. Follow if you don’t want to miss it 🔥 #javascript #frontend #codingchallenge #webdevelopment #techinterview #DAY86
To view or add a comment, sign in
-
Day 4/100 of JavaScript 🚀 Today’s focus: Functions in JavaScript Functions are reusable blocks of code used to perform specific tasks Some important types with example code: 1. Parameterized function → takes input function greet(name) { return "Hello " + name; } greet("Apsar"); 2. Pure function → same input always gives same output, no side effects function add(a, b) { return a + b; } add(2, 3); 3. Callback function → function passed into another function function processUser(name, callback) { callback(name); } processUser("Apsar", function(name) { console.log("User:", name); }); 4.Function expression → function stored in a variable const multiply = function(a, b) { return a * b; }; 5.Arrow function → shorter syntax const square = (n) => n * n; Key understanding: Functions are first-class citizens in JavaScript — they can be passed, returned, and stored like values #Day4 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 39/50 – Scope in JavaScript Today I learned about Scope in JavaScript, which defines where variables can be accessed in a program. 🔹 Scope determines the visibility and accessibility of variables. 📌 Types of Scope in JavaScript 1️⃣ Global Scope – Variables declared outside any function can be accessed anywhere. let name = "Priyanka"; function show() { console.log(name); } show(); 2️⃣ Function Scope – Variables declared inside a function are accessible only within that function. function test() { let msg = "Hello"; console.log(msg); } test(); 3️⃣ Block Scope – Variables declared with let and const inside {} are block-scoped. if(true){ let x = 10; console.log(x); } 4️⃣ Local Scope – Variables declared inside a block or function are local to that area. 💡 Key Learnings: ✅ var → function scoped ✅ let and const → block scoped ✅ Scope helps avoid variable conflicts ✅ Improves code security and readability Thanks for mentors 10000 Coders Raviteja T Abdul Rahman #Day39 #50DaysOfCode #JavaScript #WebDevelopment #FrontendDeveloper #CodingJourney #LearningEveryday
To view or add a comment, sign in
-
-
Day 2/100 of JavaScript 🚀 Today’s Topic: "let", "const", "var", hoisting and TDZ. "var", "let", and "const" are used to declare variables, but they differ in scope and initialization behavior - "var" is function-scoped and during the creation phase it gets initialized with "undefined", so it can be accessed before assignment. - "let" and "const" are block-scoped and are registered in memory during creation, but not initialized immediately. This leads to TDZ (Temporal Dead Zone) a phase where the variable exists in memory but remains uninitialized and cannot be accessed. Accessing "let" or "const" variables before initialization results in a ReferenceError. - "const" must be initialized at declaration and cannot be reassigned. - "let" allows reassignment but not redeclaration in the same scope. These differences make "let" and "const" more predictable and safer compared to "var". #Day2 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
💡 JavaScript Practice — Counting Vowels A small problem, but a good test of logic: 👉 Count the number of vowels in a string Here’s my solution: const str = "javascript"; const vowels = "aeiouAEIOU"; let count = 0; for (let letter of str) { for (let vowel of vowels) { if (letter === vowel) count++; } } console.log(count); 🧠 What this taught me: • How nested loops actually work in real scenarios • Breaking a problem into smaller steps • Writing simple, readable logic ⚡ Next step: I’ll try optimizing this (maybe using includes() or a better approach) If you have a cleaner or more efficient solution, I’d love to see it. #JavaScript #ProblemSolving #WebDevelopment #LearningInPublic
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
-
-
🚀 JavaScript String Optimization You Probably Didn’t Know When you build strings in a loop like this: let bigString = ""; for (let i = 0; i < 1000; i++) { bigString += "chunk" + i; } It looks expensive… but surprisingly, it’s not (at first). 👉 JavaScript engines are smart. Instead of immediately creating a new string every time, they use something called a ConsString (concatenated string) — a lazy structure that avoids copying data. ⚡ This means: String building stays fast and memory-efficient No actual concatenation happens yet But here’s the catch… 💥 The moment you try to access the string (like bigString[0]), JavaScript materializes it — flattening everything into a real string, which can be expensive. 📌 Key Insight: Building strings → cheap Accessing/manipulating them → can trigger hidden cost 💡 Takeaway: Performance isn’t just about what you write — it’s about when the engine does the heavy work. #JavaScript #WebPerformance #CleanCode #Programming #FrontendDevelopment #DevTips #reactjs #webdevelopment
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