colback function in JS: If you are learning JavaScript, you might have heard the term 'Callback Function.' It sounds technical, but the concept is very simple: A Callback is just a function that is passed as an argument to another function and is executed after some operation has been completed. It’s like telling JavaScript, 'Do this first, and once you're finished, run this other function! Example: let id=setInterval(() => { console.log("Vaseem baliyan"); //this is callback function }, 2000); setTimeout(() => { //2nd callback function console.log(clearInterval(id),"stoped function"); }, 12000); #JavaScript #WebDevelopment #ProgrammingTips #CodingInHindi #LearningJS #FullStack
JavaScript Callback Functions Explained
More Relevant Posts
-
I thought I understood this JavaScript concept… until I really did 👇 📌 Parameter Scope in JavaScript Function parameters are not special variables they are simply local variables scoped to the function. function greet(userName) { console.log(userName); } console.log(userName); // ❌ ReferenceError: userName is not defined Key Takeaway: userName exists only inside the function's execution context. But here’s the interesting part 👀 Parameters also follow lexical scope, which means inner functions can access them via closures: function outer(x) { function inner() { console.log(x); // ✅ Accesses 'x' from the outer scope } inner(); } And a subtle gotcha most beginners miss ⤵️ Default parameters are evaluated in their own scope at the moment the function is called, strictly before the function body begins to run. Understanding scope like this changed how I read and debug JavaScript code. Small concepts. Big clarity. 🚀 #JavaScript #WebDevelopment #LearningInPublic #Frontend #CodingTips #Scope
To view or add a comment, sign in
-
𝗪𝗲𝗹𝗰𝗼𝗺𝗲 𝘁𝗼 𝗗𝗮𝘆 𝟭𝟲 JavaScript is single-threaded. So how can it handle: • Synchronous code • Promises • Timers All at the same time? The answer is task priority and the Event Loop. In this video, I demonstrate exactly how tasks are added and executed based on priority. 𝙒𝙝𝙚𝙣 𝙘𝙤𝙙𝙚 𝙧𝙪𝙣𝙨: -> Code executes first (Call Stack). -> Promise callbacks go to the Microtask Queue. -> setTimeout callbacks go to the Macrotask Queue. 𝙃𝙤𝙬 𝙩𝙝𝙚 𝙀𝙫𝙚𝙣𝙩 𝙇𝙤𝙤𝙥 𝙋𝙞𝙘𝙠𝙨 𝙏𝙖𝙨𝙠𝙨 When the Call Stack becomes empty: -> Run ALL microtasks (Promises first). -> Then run ONE macrotask (setTimeout). -> Repeat the cycle. Microtasks always have higher priority. 𝙏𝙝𝙞𝙨 𝙥𝙧𝙞𝙤𝙧𝙞𝙩𝙮 𝙨𝙮𝙨𝙩𝙚𝙢 𝙞𝙨 𝙬𝙝𝙖𝙩 𝙖𝙡𝙡𝙤𝙬𝙨 𝙅𝙖𝙫𝙖𝙎𝙘𝙧𝙞𝙥𝙩 𝙩𝙤: • Stay responsive • Execute async logic predictably • Simulate concurrency while staying single-threaded #JavaScript #WebDevelopment #FrontendDevelopment #EventLoop #AsyncJavaScript #SoftwareEngineering #DeveloppementWeb #JavaScriptFR
To view or add a comment, sign in
-
Why const isn't actually "constant" in JavaScript 🤯 If you're new to JS, you might think const means the value can never change. But try this: const user = { name: 'Alice' }; user.name = 'Bob'; console.log(user.name); // Output: Bob Wait, what? Why didn't it throw an error? Here’s the deal: const creates an immutable binding, not an immutable value. It prevents you from reassigning the variable to a new memory address. It does NOT prevent you from changing the properties of an object or array. Key Takeaway: If you want a truly unchangeable object, use Object.freeze(). What’s a JS quirk that tripped you up when you first started? Let’s discuss below! 👇 feel free to reach me out for any career mentoring Naveen .G.R | CareerByteCode #JavaScript #WebDevelopment #CodingTips #Frontend #SoftwareEngineering
To view or add a comment, sign in
-
-
Today I learn about the Shortest code in JavaScript, guess what it is ? it is an "empty .js file" 🚀 because, when we run a empty file in js, a global execution context (GEC) sill created ✅, although it does not allocate any memory space for variables and functions but still it stores the window object inside it. Even with 0 bytes of code, the engine still creates a **Global Execution Context**. #javascript JavaScript Notes
To view or add a comment, sign in
-
-
“JavaScript is easy.” Until this happens… 🤐 console.log(1 + "11") 👉 111 😵 Wait… what? Here’s what’s happening 👇 In JavaScript, the `+` operator does TWO jobs: ➕ Math addition ➕ String concatenation If one operand is a string, JavaScript silently converts the other one into a string too. So: 1 + "11" becomes "1" + "11" = "111" This is called **Type Coercion** (implicit conversion). 🔄 And that’s just the beginning… JavaScript also has something called - Truthy & Falsy values 👇 Falsy values (remember: FUNN0""): ❌ false ❌ undefined ❌ null ❌ NaN ❌ 0 ❌ "" (empty string) Everything else? ✅ Truthy. That’s why: if ("0") { console.log("Runs") } 👉 It runs 😅 Because "0" is a string — and it's truthy. JavaScript isn’t hard. But it’s full of silent behavior that can trick you. Have you ever been stuck because of type coercion? 👇 Comment your weirdest JS bug. #JavaScript #WebDev #Frontend #CodingTips #JSLearning
To view or add a comment, sign in
-
-
🚀 Day 6 – Daily Tech Dose (JavaScript) 💡 Today’s Topic: JavaScript Hoisting Quick Question 👇 What will be the output? console.log(a); var a = 10; ✅ Answer: undefined 🧠 Why? • JavaScript hoists variable declarations (not initializations). • var a is moved to the top, but = 10 stays where it is. • So at console.log(a), a exists but has no value yet → undefined. ⚠️ Try the same with let or const and you’ll get a ReferenceError. 💬 Interview Tip • Hoisting applies to functions too (function declarations are fully hoisted). • Prefer let / const to avoid confusing bugs. ⸻ 🔖 Hashtags #JavaScript #WebDevelopment #Frontend #Programming #CodingInterview #LearnJS #TechDaily #100DaysOfCode #VivekVishwakarma Want Day 7 next? 😄
To view or add a comment, sign in
-
-
💠 JavaScript slice() Method — Explained Simply The slice() method is used to extract a portion of an array or string without modifying the original data. It returns a new array or string, making it a non-mutating and safe operation. 🔍 Key Characteristics 🔸 Does not mutate the original array or string 🔸 Supports negative indexes 🔸 Commonly used for copying arrays, pagination, and sub-list creation 👉 Real-World Use Case 🔹 In React applications, slice() is often used for: 🔹 Pagination 🔹 Displaying partial lists 🔹 Maintaining immutability during state updates 💡 Why it matters 🔹 In React and modern JavaScript, immutability is key. 🔹 slice() helps maintain clean, predictable state updates. #JavaScript #FrontendDevelopment #ReactJS #WebDevelopment #CodingTips #LearnJavaScript #Programming
To view or add a comment, sign in
-
-
Big news for JavaScript developers: the Explicit Resource Management proposal is making it much easier to clean up resources in your code. At its core, this effort introduces a standardized cleanup pattern and a new using keyword that lets you tie disposal logic directly to a variable’s scope; meaning things like sockets, streams, and generators can be reliably cleaned up when they’re no longer needed. This brings greater predictability to resource management and reduces the risk of leaks or dangling connections. The proposal has already reached Stage 3 of the standards process and is implemented in most major browsers (except Safari), giving you a chance to experiment with it now. Key takeaways for dev teams: 🔹 Common cleanup methods like .close(), .abort(), etc., get a consistent pattern via [Symbol.dispose] 🔹 The using declaration ensures automatic cleanup at the end of a scope 🔹 Helps write safer, more maintainable code with fewer manual resource errors If you care about robustness and clarity in your JavaScript projects, this change is worth exploring. #JavaScript #WebDevelopment #CleanCode #ECMAScript #Programming #SoftwareEngineering
To view or add a comment, sign in
-
Day 8 of 15 –Learn Frontend in 1 Minute JavaScript doesn’t run magically in the browser. It follows a very strict order. There is only one main thread. Only one thing can run at a time. What confuses most developers is this: JavaScript can start async work, but it doesn’t execute it in parallel. When you call setTimeout, fetch data, or attach events: -JavaScript hands the task to the browser -continues running the next line -comes back later when the stack is free This is why code sometimes logs in an unexpected order. Nothing is random. The rules are just invisible at first. Once you understand that JavaScript never multitasks, a lot of “weird” bugs stop being weird.
To view or add a comment, sign in
-
-
Just caught a classic JavaScript mistake that had me scratching my head for a second! 🤦🏾♂️ I was setting up form validation with `blur` event listeners, and my validation functions were running immediately on page load instead of waiting for the user to leave the field. The culprit? I forgot to remove the parentheses when passing functions to event listeners When you include the parentheses `()`, JavaScript calls the function immediately and passes its return value to the event listener (which is usually `undefined`). Without the parentheses, you're passing a reference to the function itself, which gets called later when the event fires. It's a subtle difference, but it completely changes the behavior. The function reference waits for the event; the function call happens right away. A quick fix this time,thankfully. Easily done. #JavaScript #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