Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the concept of javascript pure function

Shulou Source: shulou.com Published: 2022-05-31 11:55:34 09月29日 Update

This article mainly explains "what is the concept of javascript pure function". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the concept of javascript pure function".

Description

1. Pure functions are similar to functions in mathematics, which are used to describe the relationship between input and output.

2. For pure functions, it has the characteristic that the same input must have the same output, so when the pure function is called many times, it can be cached to improve performance.

Example

/ / Pure function function getArea (r) {console.log (r) / / it will be printed three times. Remember that we will modify it later and do a cache. This is also the advantage of pure function return Math.PI * r * r} console.log (getArea (4)) / / 50.26548245743669console.log (getArea (4)) / / 50.26548245743669console.log (getArea (4)) / / 50.26548245743669 / impure function let numbers = [1,2,3,4,5] numbers.splice (0,3) / / = > [1,2,3] numbers.splice (0,3) / = > [4,5] numbers.splice (0) 3) / / = > [] Thank you for your reading The above is the content of "what is the concept of javascript pure function". After the study of this article, I believe you have a deeper understanding of what the concept of javascript pure function is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Functions concepts learning same content cache input output between advantages examples that is ideas performance situation location mathematics articles more features Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Microsoft Redmi Xiaomi