🚀 30 Days of JavaScript Tricky Questions – Day 2 🧠 Topic: Closures in JavaScript function outer() { let outerVar = "I am from outer function!"; function inner() { let innerVar = "I am from inner function!"; console.log(outerVar); console.log(innerVar); } return inner; } const myClosure = outer(); myClosure(); Can you guess what should be logs in the console🤔 💬 Drop your answer in the comments #JavaScript #JSClosures #FrontendDeveloper #WebDevelopment #100DaysOfCode #LearningJavaScript #InterviewPrep
Closures in JavaScript Explained
More Relevant Posts
-
I learned about truthy and falsy values in JavaScript. Non-zero numbers, non-empty strings, arrays, and objects return truthy values. On the other hand, 0, empty strings (""), null, and undefined are falsy. Understanding truthy and falsy behavior helps a lot when working with conditions and logical statements. Strengthening my JavaScript fundamentals step by step. #JavaScript #ProgrammingBasics #WebDevelopment #LearningJourney
To view or add a comment, sign in
-
🚀 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
To view or add a comment, sign in
-
-
✨ Object Methods in JavaScript Objects are one of the most fundamental parts of JavaScript, and knowing how to work with them efficiently can make your code much more powerful and readable. In today’s post, I’ve covered important object methods in JavaScript that every developer should know. Understanding these methods helps you manipulate data structures more effectively and write cleaner, more efficient code. If you work with JavaScript regularly, mastering object methods is definitely a must. 👇 Which JavaScript object method do you use the most in your projects? Follow Muhammad Nouman for more useful content #learningoftheday #1000daysofcodingchallenge #FrontendDevelopment #WebDevelopment #JavaScript #React #Next #CodingCommunity
To view or add a comment, sign in
-
Variables in JavaScript Most beginners learn variables in JavaScript… But very few understand values first. And without understanding values, JavaScript can feel confusing. Let’s make it simple. 👇 In JavaScript, a value is simply data stored in memory. When you write code like: let age = 25; 👉 age = variable 👉 25 = value Here are some common JavaScript values: • Number → 10, 3.14, 100 • String → "Hello", "JavaScript" • Boolean → true or false • Null / Undefined → empty or missing values • Objects & Arrays → complex values like {} and [] Think of it like this: 📦 Variable = Box 🎁 Value = What’s inside the box JavaScript programs run by creating, storing, and using values all the time. If you understand values well, the rest of JavaScript becomes much easier. #JavaScript #WebDevelopment #FrontendDevelopment #ProgrammingBasics #JavaScriptTips #LearnToCode #CodingForBeginners #SoftwareDevelopment #JSDeveloper #TechEducation
To view or add a comment, sign in
-
-
Arrays are everywhere in JavaScript. I wrote a guide explaining the most useful JavaScript array methods with clear examples. Check it out! https://lnkd.in/gmAp5n8b Thank you sir, Hitesh Choudhary Piyush Garg Akash Kadlag Anirudh J. Nikhil Rathore from Chai Aur Code
To view or add a comment, sign in
-
-
🚀 30 Days of JavaScript – Day 12 Can you solve these number puzzles? 🤔 Today I built a small JavaScript program that asks 3 number pattern questions and calculates the final score. 🧠 Concepts Used: conditional statements user input with prompt() variables and score tracking 🎥 Demo below 👇 Full source code in the First comment. #JavaScript #CodingChallenge #ProblemSolving #LearningJavaScript #WebDevelopment
To view or add a comment, sign in
-
🚀 Day-22 — Revisiting JavaScript Basics Today I went back to JavaScript fundamentals and revised some important concepts. I focused on: • Throttling — limits how often a function runs Example: window.addEventListener("scroll", throttle(handleScroll, 2000)) • Debouncing — runs a function only after a delay (when user stops action) Example: input.addEventListener("input", debounce(handleSearch, 500)) • Promises — handle async operations with success/failure Example: fetch(url).then(res => res.json()).then(data => console.log(data)) • Asynchronous JavaScript — allows non-blocking execution Example: async function getData(){ const res = await fetch(url) const data = await res.json() } Revisiting these basics helped me understand them more clearly and how they actually work in real projects. Going back to fundamentals always helps. Ankur Prajapati Satwik Raj #JavaScript #WebDevelopment #LearningInPublic #BuildInPublic#21daysofcoding#sheriyans
To view or add a comment, sign in
-
Got a minute for some JavaScript? 😚 What does this code output? Answer 🔍 >>> undefined I don’t really like questions where you just have to be attentive, but I think this is something worth paying attention to. To get the number of entries in a *Map*, you use the *.size* property, not *.length* like in arrays. In short: .length --> Arrays, Strings, function parameters .size --> Map, Set #javascript #webdevelopment
To view or add a comment, sign in
-
-
Today I learned about one of the most important concepts in JavaScript: The Event Loop. JavaScript is single-threaded, which means it can run only one task at a time. But it can still handle asynchronous operations like timers, API calls, and user events. This is possible because of the Event Loop. 💡 How it works: 1️⃣ Call Stack – Executes JavaScript code 2️⃣ Web APIs – Handles async tasks like setTimeout, fetch, DOM events 3️⃣ Callback Queue – Stores completed async callbacks 4️⃣ Event Loop – Moves tasks from the queue to the stack when it’s empty Example: console.log("Start"); setTimeout(() => { console.log("Timer"); }, 2000); console.log("End"); Output: Start End Timer The timer runs later because it goes through the Event Loop system. Understanding the event loop helps in writing better async JavaScript and debugging complex behavior. Day 5 of my 21 Days JavaScript Concept Challenge 🚀 #JavaScript #WebDevelopment #FrontendDeveloper #AsyncJavaScript #LearningInPublic
To view or add a comment, sign in
-
-
💻 JavaScript Intermediate – Custom map() Function The map() method is widely used to transform arrays. Here’s how you can implement it manually. 📌 Problem: Apply a function to each element of an array and return a new array. function customMap(arr, callback) { let result = []; for (let i = 0; i < arr.length; i++) { result.push(callback(arr[i])); } return result; } let numbers = [1, 2, 3]; let doubled = customMap(numbers, function(num) { return num * 2; }); console.log(doubled); 📤 Output: [2, 4, 6] 📖 Explanation: • map() creates a new array by applying a function to each element. • Here, we manually implemented the same logic using a loop and callback. 💡 Tip: Understanding this helps you grasp how higher-order functions work in JavaScript. #JavaScript #Coding #WebDevelopment #FrontendDevelopment #LearnToCode #ProgrammingTips
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
I am from outer function! I am from inner function!