Functional programming is a declarative programming paradigm where programs are created by applying sequential functions rather than statements.
Each function takes in an input value and returns a consistent output value without altering or being affected by the program state.
These functions complete a single operation and can be composed in sequence to complete complex operations. The functional paradigm results in highly modular code, since functions can be reused across the program and can be called, passed as parameters, or returned. https://www.educative.io/blog/what-is-functional-programming-python-js-java
It returns the same if given the same arguements. They also produce no side effects and do not depend on global veriables or states.
- Easy debugging: Pure functions and immutable data make it easy to find where variable values are set. Pure functions have fewer factors influencing them and therefore allow you to find the bugged section easier.
- Lazy evaluation: Functional programs only evaluate computations at the moment they’re needed. This allows the program to reuse results from previous computations and save runtime.
- Modular: Pure functions do not rely on external variables or states to function, meaning they’re easily reused across the program. Also, functions will only complete a single operation or computation to ensure you can reuse that function without accidentally importing extra code.
- Enhanced readability: Functional programs are easy to read because the behavior of each function is immutable and isolated from the program’s state. As a result, you can predict what each function will do often just by the name!
- Parallel programming: It’s easier to create parallel programs with a functional programming approach because immutable variables reduce the amount of change within the program. Each function only has to deal with user input and can trust that the program state will remain mostly the same! https://www.educative.io/blog/what-is-functional-programming-python-js-java
The state cannot be changed after it is created.
In functional programming, referential transparency is generally defined as the fact that an expression, in a program, may be replaced by its value (or anything having the same value) without changing the result of the program. This implies that methods should always return the same value for a given argument, without having any other effect. This functional programming concept also applies to imperative programming, though, and can help you make your code clearer. https://www.sitepoint.com/what-is-referential-transparency/
Essentially another javascript file.
It creates a path to the other modules to be able to use the variable globally.
module.exports = (whatever function you want to pull in); with a require in the other module
This seems like like the same answer, but by specifying a path and which function you want it should pull through.