function <functionName>(<arg1>, ... <argN>){  
 //code to be executed  
 return <expression>
function sum(a, b) {
    return a+b;

Passing arguments

Primitive parameters such as a number are passed to functions by value. This means that when the function changes the value of the parameter, this change is not reflected globally or in the calling function.
If you pass an object as a parameter and the function changes the object's properties, that change is visible outside the function.

Default values of arguments

Default values of parameters is undefined value. Also you can assign a default value explicity.

function mul1(a, b) {
  b = typeof b !== 'undefined' ?  b : 1;
  return a * b;

function mul2(a, b = 1) {
  return a * b;

var z = mul2(45);

Arbitrary number of arguments

JavaScript supports the use of an arbitrary number of arguments.
For every function a arguments array defined. It stores all the arguments passed. So, you can access to unnamed arguments by index.

function strConcat(separator) {
   var result = '', i; 
   for (i = 1; i < arguments.length; i++) {
      result += arguments[i] 
          result += separator;
   return result;
// fruits will be equal to "apple,watermelon,grape"
var fruits = strConcat(',' "apple", "watermelon", "grape")

undescore argument

First, the underscore _ is a valid JavaScript identifier.

Second, a single underscore is a convention used by some javascript programmers to indicate to other programmers that they should ignore this binding/parameter.

this.myfunc = function(_){
    console.log('Hello, World!');

// it can be rewritten as
this.myfunc = function(){
    console.log('Hello, World!');

// ignore binding of the first parameter 
// in callback
array.forEach(function (_, i) {...});


JavaScript support closure.
It allows for the nesting of functions. The inner function has full access to all variables and functions defined inside the outer function. Even if the internal function will live longer than the external.
The outer function does not have access to the variables and functions defined inside the inner function.