A Function is much the same as a Procedure or a Subroutine, in other programming languages.
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce different results.
Function Declaration (function statement)
Self-Invoking Function (Immediately Invokable Function ExpressionIIFE)
Object Method Shorthand Definition
Function parameters are listed inside the parentheses () in the function definition.
Function arguments are the values received by the function when it is invoked.
Inside the function, the arguments (the parameters) behave as local variables.
1. Function Declaration (function statement)
When a function declaration is created, a variable named as function name is created as well. This variable is hoisted top of the current scope. In other words, variable is moved to top of current scope. This means that the function can be called before the function declaration
//If you have installed babel-cli package globally, run below code.
babel-node --presets=env --plugins=transform-runtime src
//If you have .babelrc config file, run below code without specifying inline arguments.
//If you have installed babel-cli package locally, run below code.
./node_modules/.bin/babel-node --presets=env --plugins=transform-runtime src
Running with Babel-register
node --require ./node_modules/babel-register src
node --require babel-register src/index.js