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.
Pure functions are stable, consistent, and predictable. Given the same parameters, pure functions will always return the same result. We don’t need to think of situations when the same parameter has different results — because it will never happen.
The code’s definitely easier to test. We don’t need to mock anything.
Immutables are the objects whose state cannot be changed once the object is created. Strings and Numbers are Immutable.
Basically, if a function consistently yields the same result for the same input, it is referentially transparent.
pure functions + immutable data = referential transparency
Referential transparency and referential opacity are properties of parts of computer programs. An expression is called referentially transparent if it can be replaced with its corresponding value (and vice-versa) without changing the program’s behavior.
Module in Node. js is a simple or complex functionality organized in single or multiple JavaScript files which can be reused throughout the Node. js application. Each module in Node. js has its own context, so it cannot interfere with other modules or pollute global scope.
method is used to load and cache JavaScript modules. So, if you want to load a local, relative JavaScript module into a Node. js application, you can simply use the require()
method.
require()
is used to consume modules. It allows you to include modules in your app. You can add built-in core Node.js modules, community-based modules (node_modules), and local modules too.
The basic functionality of require is that it reads a JavaScript file, executes the file, and then proceeds to return the exports object. It is worth noting that each time you subsequently require an already-required file, the exports object is cached and reused.
by creating a JavaScript file. Every time you create a new file with .js extension, it becomes a module.
The first thing you do to get access to module features is export them. This is done using the export statement.
Basiclly export it by useing module.export.