Linked Questions

1 vote
2 answers
95 views

In the following example, when the button is clicked, cb2 uses the memoized function. However, why doesn’t cb2 use the first render closures (countVal: 0)? function TestHook() { const [count, ...
2tuzi's user avatar
  • 66
0 votes
0 answers
87 views

A closure is basically an inner/nested function. What are some of the most common examples of nested functions in popular js frameworks? In what scenarios would you choose to write a custom closure?
user6411982's user avatar
1 vote
0 answers
70 views

I will use a debounce function as example. const debounce = (func, wait) => { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); ...
entropyfeverone's user avatar
0 votes
0 answers
94 views

const throttle = <T extends unknown[]>( callback: (...args: T) => void, delay: number, ) => { // this is not a global variable, just a local variable ?? let isWaiting = false; ...
Flo19's user avatar
  • 91
17 votes
3 answers
16k views

I'm a web developer, but lots of folks are looking for slightly more advanced skills and understanding closures seems to be at the forefront of this. I get the whole "execution context creating a ...
qodeninja's user avatar
  • 11.3k
15 votes
4 answers
8k views

I understand what a nested function is, but I don't understand why we even need nested functions in the first place. Is there a problem that can only be solved by using nested functions in JavaScript. ...
Mahtab Alam's user avatar
  • 1,870
2 votes
2 answers
9k views

everyone. I have a problem about the 'callback function - scope of variable', I wanna use the 'i in for loop' to 'the callback function User_UidSearch', but I cannot use it. (I hope the solution ...
Salmon's user avatar
  • 133
4 votes
3 answers
4k views

I have used JS for two years and my pluralsight accessment rates me as proficient in JS, I understand prototypical inheritance, higher order functions, IIFEs etc and I have used them in real world ...
user avatar
1 vote
3 answers
2k views

In the below code, variable text is not accessible in the findTextToDelete function (it generates an error) array = ['a', 'b', 'removeThis', 'c']; removeText("removeThis"); function ...
remjx's user avatar
  • 4,650
0 votes
1 answer
3k views

I'm new to javascript and I'm having trouble using the setInterval() function properly. Basically I want to call a function at different given intervals for different parameters both of which I have ...
Saxman13's user avatar
0 votes
1 answer
2k views

I have access to each of the li[i] that returns what you see in the picture. An example would be li[i].innerText returns business. How can I get the checked state of each element? //loop through ...
LeggoMaEggo's user avatar
0 votes
3 answers
1k views

I would like to know how to pass data by value, rather than by reference, into a then handler on a jQuery Deferred object. I have the following example code to illustrate my question: var value; var ...
Alex Bowyer's user avatar
-1 votes
1 answer
749 views

I understand that in Javascript a function can return another function and it can be called immediately. But I don't understand the reason to do this. Can someone please explain the reason and benefit ...
user1142130's user avatar
  • 1,645
0 votes
1 answer
690 views

In the You Don't Know Javascript series, 1/3 of the way down IIFE's are described as not being closures themselves, but only if they're executed outside their lexical scope: Chapter 3 introduced the ...
user3871's user avatar
  • 12.7k
0 votes
3 answers
858 views

A common pitfall with JavaScript closures is running setTimeout() from a for loop, and expecting the counter to be passed with different values at each iteration, while in practice it gets assigned ...
Dan Dascalescu's user avatar

15 30 50 per page