Skip to main content
InterviewHubPRO
Section Overview
Q358

Question 358 of 536

Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

67%
JavaScript & V8 Internals (536 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

What is a thunk function

senior LevelCode ExampleAsync & PromisesEvent LoopHTTP & REST APIs

A thunk is just a function which delays the evaluation of the value. It doesn’t take any arguments but gives the value whenever you invoke the thunk. i.e, It is used not to execute now but it will be sometime in the future. Let's take a synchronous example,

javascript
  const add = (x, y) => x + y;

  const thunk = () => add(2, 3);

  thunk(); // 5