- Redux Quick Start Guide
- James Lee Tao Wei Suresh Kumar Mukhiya
- 172字
- 2021-07-02 12:40:29
Pure functions
The most common definition of a pure function is a function that does not have side effects. This is to say that the returned value of a pure function is not affected, influenced, or changed by anything other than its input parameters. Provided the same input, the pure function always generates the same output. An example is as follows:
const sum = (a, b) => a + b;
This is an example of a pure function. Assuming that you call the function sum(6,9), the result is always 15, irrespective of the number of times that you run the function. You can be confident, if you are calling a pure function with the same input, that you are always going to get the same output, which means that the output is predictable. An example of an impure function is the following square function. In addition to returning the square of the number, the function might be updating the number in a database:
function square(number) {
updateNumberInDB(number);
return number * number;
}
- Mastering Adobe Captivate 2017(Fourth Edition)
- What's New in TensorFlow 2.0
- Learning Apex Programming
- Bulma必知必會
- Swift細致入門與最佳實踐
- Mastering JavaScript High Performance
- 青少年信息學競賽
- 第一行代碼 C語言(視頻講解版)
- Python深度學習原理、算法與案例
- JavaScript應用開發實踐指南
- 后臺開發:核心技術與應用實踐
- PyQt編程快速上手
- Secret Recipes of the Python Ninja
- Mudbox 2013 Cookbook
- JavaScript高級程序設計(第4版)