Pure Function
noun
say it: “PYOOR FUNGK-shun” /pjʊr ˈfʌŋkʃən/
A function that always gives the same answer for the same inputs and changes nothing outside itself, so you can test it with no setup.
What is Pure Function in JavaScript?
Pure Function — A function that produces the same result for the same inputs without changing outside state.
function total(price, quantity) {
return price * quantity;
}
In a sentence
- “I moved the price math into a pure function so the tests didn't need a browser.”
- “formatTime is a pure function: give it 90 and it returns "1:30" every time, without touching the page.”
Level: Journeyman · More JavaScript terms at this level
Updated