Defining functions

There is many ways to define a function. Here's a list of most commoly used ones.

Basic declaring

function robot(diamond) {  

Function expressions

Difference to variable scope handling, function expressions are not hoisted in the start of the scope.

Benefit of named functions is that on error situations stack trace will contain the name of the function. In this example pete is the name of the function.

// Anonymous function expression
var robot = function(diamond) {  

// Named function expression
var robot = function pete(diamond) {  

Immediately Invokable Function Expressions (IIFE)

When function needs to be invoked as soon as it's declared.

(function() {


This is ES6 short form for function declaration. If there is only one parameter, parentheses are not needed. Same goes with statement block. With only one expression, brackets are not needed.

(diamond) => {

diamond => console.log(diamond)