Skip to content

Latest commit

 

History

History
17 lines (10 loc) · 598 Bytes

what_is_a_thunk_function.md

File metadata and controls

17 lines (10 loc) · 598 Bytes

What is a thunk function?

A thunk function is a function that wraps another function or expression, typically used to delay the execution of the original function. It is often used in functional programming to manage side effects or control execution order.

Example:

const add = (a, b) => a + b;
const thunk = (a, b) => () => add(a, b);
const result = thunk(2, 3)();  // Output: 5

Tags: advanced, JavaScript, Functional Programming