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

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;
}
主站蜘蛛池模板: 富阳市| 吉安市| 攀枝花市| 天门市| 英山县| 确山县| 成安县| 高阳县| 班玛县| 巴塘县| 沙洋县| 上栗县| 额济纳旗| 会宁县| 宁海县| 四平市| 巴林右旗| 开江县| 汝南县| 肥乡县| 遂溪县| 甘孜县| 临猗县| 平远县| 和林格尔县| 苗栗县| 上犹县| 道真| 镇平县| 大兴区| 衡东县| 谢通门县| 桦甸市| 大丰市| 淅川县| 新宁县| 花莲市| 容城县| 高台县| 汉阴县| 砚山县|