官术网_书友最值得收藏!

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;
}
主站蜘蛛池模板: 图木舒克市| 胶州市| 封丘县| 安福县| 甘泉县| 浦江县| 全州县| 云龙县| 玉环县| 梓潼县| 三江| 建德市| 通江县| 荥经县| 徐州市| 淳化县| 昂仁县| 大英县| 甘洛县| 肃南| 万盛区| 雷州市| 太谷县| 融水| 大荔县| 深泽县| 阿坝| 门头沟区| 通海县| 彭州市| 湖口县| 同仁县| 中牟县| 北川| 沈丘县| 肇东市| 容城县| 外汇| 婺源县| 临漳县| 辽阳市|