Functional programming is a programming paradigm — a style of building the structure and elements of computer programs — that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. Programs are constructed by composing functions and applying them to data.
A pure function is a function that, given the same input, will always produce the same output and has no side effects. They are highly desirable in functional programming because they are easier to reason about, test, and parallelize.
The benefits of pure functions include improved code quality, maintainability, testability, and the ability to leverage parallelism and caching techniques. By adhering to the principles of functional programming and maximizing the use of pure functions, developers can create a reliable software system.
This is the property of an object or data structure that cannot be modified after it is created. Immutable objects or data structures cannot be changed in-place and instead, any operation that appears to modify them actually creates a new object or structure with the desired changes.
A function is referentially transparent if it consistently produces the same output for the same input and has no side effects.
A self-contained unit of code that encapsulates related functionality. It is a way to organize and structure code by grouping together functions, classes, variables, and other elements that work together to achieve a specific purpose.
In JavaScript, particularly in the Node.js environment, the ‘require’ keyword is used to import modules or files that contain reusable code.
Use the ‘import’ keyword to bring in functionality from other modules.
To make a module available for use in other parts of a program, you need to define the module by creating a separate file, export the desired elements, and import the module in the file where you want to use the module.