Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

thunk
lazy evaluation
function

What is a "thunk"?

Educative Answers Team

Thunk is a function that wraps another function or expression to delay computation. Thunk can also be used to add additional calculations to a function.
Thunks provide lazy evaluation and are widely used in functional programming languages.

If you are looking for Redux Thunk, check out this shot.

Example

Here’s an example of using a thunk myFunction to delay evaluation of an expression in JavaScript:

// calculation of 1 + 2 is immediate
let x = 1 + 2;
 
// calculation of 1 + 2 is delayed
// myFunction can be called later to perform the calculation
let myFunction = () => 1 + 2;

Applications

  • Functional programming and lazy evaluation
  • Inheritance of multiple interfaces in object-oriented programming
  • Interoperability between software modules

RELATED TAGS

thunk
lazy evaluation
function
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring