Is JavaScript considered a functional programming language or not

What are the special requirements for the use of functions in functional programming? .

  • Declarative.

  • Pure Function.

  • Data immutability.

From a language perspective, JavaScript is not a purely functional programming language, but functions in JavaScript have the status of first citizens because functions themselves are objects that can be assigned to variables and passed as parameters, making it easy to apply many ideas of functional programming.

We view functional programming as a programming philosophy, and even if the language itself does not support certain features, we can still apply this programming philosophy to improve the quality of code. So JavaScript is not purely a functional programming language, but by applying some programming conventions and with the help of a few tools, we can write functional code using JavaScript. RxJS is a tool that assists us in writing functional code.

How JavaScript Meets the Feature Needs of Functional Programming .

1. Declarative.

The programming method that corresponds to declarative programming is called Imperative Programming, and imperative programming is also the most common programming method.

2. Pure functions.

  • The execution process of a function is entirely determined by the input parameters and is not affected by any data other than the parameters
  • The function does not modify any external state, such as modifying global variables or incoming parameter objects.

3. Data immutability.

When we need a change in data state, we keep the original data unchanged and generate a new data to reflect this change. The immutable data is the immutable data, and once it is generated, it can be guaranteed that its value will never change, which is very beneficial for understanding the code.

Understanding Responsive Programming: .

Calculating the sum of several data in an Excel spreadsheet is one form of response.

Reactive Extension: ReactiveX, Rx. .

RxJS has the characteristics of both functional and responsive programming methods. .

Talking about the application of functions in daily work: .

We usually extract some common and frequently used business logic into a common function. When a function is needed in multiple places, we only need to call this function to complete the corresponding business. The benefits of using functions are self-evident.

In fact, there is a saying that describes software development as follows: the vast majority of problems encountered in the programming world can be solved using the idea of encapsulation. To exaggerate, all the code that can be seen is actually encapsulated code.