- 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 NetBeans
- Java異步編程實戰(zhàn)
- Xcode 7 Essentials(Second Edition)
- Python從菜鳥到高手(第2版)
- C語言程序設(shè)計
- Windows Forensics Cookbook
- Serverless架構(gòu)
- Learning Three.js:The JavaScript 3D Library for WebGL
- Flutter跨平臺開發(fā)入門與實戰(zhàn)
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲案例實戰(zhàn)全流程詳解(入門與提高篇)
- Swift 4 Protocol-Oriented Programming(Third Edition)
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- Django 3.0入門與實踐
- Xcode 6 Essentials
- R Data Science Essentials