![]() |
VOOZH | about |
The JavaScript Pipeline Operator (|>) is used for passing the result of one expression into a function. It's particularly useful for making long chains of functions easier to read. With this operator, the value before it gets sent as input to the function that follows. You simply arrange the functions in the order you want them to act on the input.
Syntax:
expression |> functionAs the Pipeline Operator is an experimental feature and currently in stage 1 proposal, there is no support for currently available browsers and therefore is also not included in Node. However, one can use Babel (JavaScript Compiler) to use it.
npm initnpm install @babel/cli @babel/core
@babel/plugin-proposal-pipeline-operator {
"plugins":
[
[
"@ babel/plugin-proposal-pipeline-operator",
{
"proposal" : "minimal"
}
]
]
}"start" : "babel main.js --out-file output.js && node output.js"npm startExample: This exmaple shows the use of Pipeline Operator.
Output:
20
20