📚 Today I Learned: Scope Chain in JavaScript The scope chain in JavaScript is used to resolve variable values. When a variable is used, JavaScript looks for it in a specific order. 🔹 How it works: 1️⃣ JavaScript first checks the current scope. 2️⃣ If the variable is not found, it checks the outer (parent) scope. 3️⃣ This process continues until it reaches the global scope. 💻 Example: let a = 10; function outer() { let b = 20; function inner() { let c = 30; console.log(a, b, c); } inner(); } outer(); ✅ The inner() function can access c, b, and a because of the scope chain. #javascript #webdevelopment #frontenddeveloper #learninginpublic
Understanding JavaScript Scope Chain
More Relevant Posts
-
💡 JavaScript Trick Question: 3 + 2 + "7" In JavaScript, the answer is: 👉 "57" 🔍 Why? 🔹 JavaScript follows left-to-right evaluation and uses type coercion. ⚡ Key Insight : 🔹Once a string enters the expression, everything after that becomes a string operation. "In JavaScript, the moment a string joins the party, numbers stop adding and start concatenating." #JavaScript #WebDevelopment #CodingInterview #Frontend #JSConcepts
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 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 Concept: Hoisting Explained Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their scope before execution. This is why we can sometimes use variables or functions before they are declared. Example: console.log(name); // undefined var name = "Arun"; Why undefined? Because JavaScript internally treats it like this: var name; console.log(name); name = "Arun"; 🔹 Important Points: • "var" is hoisted and initialized with "undefined" • Function declarations are fully hoisted • "let" and "const" are hoisted but stay in the Temporal Dead Zone (TDZ) ⚠️ Accessing "let" or "const" before declaration will throw an error. 📌 Best Practice: Avoid relying on hoisting — always declare variables at the top for better readability. #javascript #frontenddevelopment #reactjs #webdevelopment #coding
To view or add a comment, sign in
-
-
⚡ 1-Minute JavaScript Quickly check if all values in an array are truthy using a clean one-liner. Utility function :- const allTruthy = (arr) => arr.every(Boolean); //Usage :- allTruthy([1, "hello", true]); // true allTruthy([1, "", true]); // false 💡 Why this works: Array.every() checks if every element passes a condition. Passing Boolean converts each value to true or false. So it effectively checks if every value is truthy. 🔎 Values considered falsy in JavaScript: • false • 0 • "" (empty string) • null • undefined • NaN ⚙️ Practical use cases: ✔ Form validation ✔ API response checks ✔ Ensuring required values exist before processing Clean. Expressive. Very JavaScript. #JavaScript #FrontendDevelopment #CleanCode #WebDevelopment #DevTips
To view or add a comment, sign in
-
-
Day 12 #100DaysOfCode 💻 Today I learned about Synchronous vs Asynchronous JavaScript, especially how setTimeout() and setInterval() work. JavaScript runs code synchronously by default (line by line). But functions like "setTimeout()" run asynchronously, meaning they execute later without blocking the main thread. Example: console.log("1"); setTimeout(() => { console.log("2"); }, 0); console.log("3"); Output: 1 3 2 Even with "0ms", "setTimeout" goes to the callback queue, so the synchronous code runs first. Understanding this concept helped me see how JavaScript handles non-blocking tasks. #JavaScript #AsyncJavaScript #WebDevelopment #CodingJourney #Akbiplob
To view or add a comment, sign in
-
✨ 𝗗𝗮𝘆 𝟮𝟮 𝗼𝗳 𝗠𝘆 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 🚀 (𝗙𝗶𝗻𝗮𝗹 𝗗𝗮𝘆 𝗼𝗳 𝗝𝗦 𝗙𝘂𝗻𝗱𝗮𝗺𝗲𝗻𝘁𝗮𝗹𝘀) Today I learned about the 𝘁𝗵𝗶𝘀 𝗸𝗲𝘆𝘄𝗼𝗿𝗱 and how its value changes in different scenarios in JavaScript. I explored how 𝘁𝗵𝗶𝘀 behaves in: 🔹 Global context 🔹 Regular functions 🔹 Object methods 🔹 Arrow functions 🔹 Constructor functions / classes I also learned how to control 𝘁𝗵𝗶𝘀 using 𝗰𝗮𝗹𝗹(), 𝗮𝗽𝗽𝗹𝘆(), 𝗮𝗻𝗱 𝗯𝗶𝗻𝗱(). Another important concept was understanding 𝗦𝘁𝗿𝗶𝗰𝘁 𝗠𝗼𝗱𝗲 𝘃𝘀 𝗡𝗼𝗻-𝗦𝘁𝗿𝗶𝗰𝘁 𝗠𝗼𝗱𝗲. In strict mode ("𝘂𝘀𝗲 𝘀𝘁𝗿𝗶𝗰𝘁"), JavaScript enforces stricter rules and prevents some common mistakes. For example, inside a regular function this becomes undefined instead of the global object, making behavior more predictable. Finishing these JavaScript fundamentals feels great. Now it’s time to move forward and build more complex projects! 💪 #JavaScript #100DaysOfCode #WebDevelopment #LearningJourney #FrontendDevelopment
To view or add a comment, sign in
-
-
Got a minute for some JavaScript? 🍵 What does this code output? Answers 🔍 >>> - ReferenceError: message is not defined Why? Because let lives only inside the block where it’s created. In this code, message is created inside the *if {}* and *else {}* blocks. When JavaScript reaches *console.log(message)*, it is already outside those blocks, so the variable no longer exists. #javascript #webdevelopment
To view or add a comment, sign in
-
-
Today I practiced the difference between map(), filter(), and forEach() in JavaScript. map() creates a new array by transforming each element of the original array. filter() creates a new array with elements that satisfy a specific condition. forEach() simply runs a function for each element and does not return a new array. Understanding these methods makes working with arrays much easier and cleaner. #JavaScript #WebDevelopment #ArrayMethods #LearningJourney
To view or add a comment, sign in
-
If strings in JavaScript are primitives, how can we call methods like .split()? "hello".split("") At first this looks strange, because primitives are not objects. The reason it works is because JavaScript does something behind the scenes called auto-boxing. When you call a method on a string, JavaScript temporarily wraps the primitive into a String object, runs the method, and then removes the object. That’s why primitives like strings can still use methods. And this also explains this behavior "hello" === new String("hello") // false Because one is a primitive and the other is an object. #javascript
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