Immediate function using JavaScript ES6 arrow functions Immediate function using JavaScript ES6 arrow functions javascript javascript

Immediate function using JavaScript ES6 arrow functions


From the Arrow functions examples,

(() => "foobar")() // returns "foobar" 

So, the function invocation operator should be outside.

(() => {  //...})();

Sample: http://www.es6fiddle.net/hsb8s1sj/


Here is my demo codes!

Always remember that function_name+() === function_caller

/* ES5 */// normal functionfunction abc(){    console.log(`Hello, ES5's function!`);}abc();var abc = function xyz(){    console.log(`Hello, ES5's function!`);};abc();// named functionvar abc = function xyz(){    console.log(`Hello, ES5's function!`);}();// anonymous function// 1(function(){    console.log(`Hello, ES5's IIFE!`);})();// 2(function(){    console.log(`Hello, ES5's IIFE!`);}());// 3var abc = function(){    console.log(`Hello, ES5's function!`);}();/* ES6 */// named arrow functionconst xyz = () => {    console.log(`Hello, ES6's Arrow Function!`);};xyz();const xyz = (() => {    console.log(`Hello, ES6's Arrow Function!`);})();// Uncaught SyntaxError: Unexpected token (/*const xyz = (() => {    console.log(`Hello, ES6's Arrow Function!`);}());*/// anonymous arrow function(() => {    console.log(`Hello, ES6's Arrow Function!`);})();