JS - 5 kinds of functions

13 Sep 2020

1. Named function

function hello() {
  console.log('hello');
}

2. Anonymous function

var hello = function() {
  console.log('hello');
}

3. Object method

var obj = {
  hello: function() {
    console.log('hello')
  }
}

4. Object method(ECMAScript 2015 version)

var obj = {
  hello() {
    console.log('hello')
  }
}

5. IIFE(Immediately invoked function expression)

var IIFE = (function() {
  console.log('hello');
})();
Back to top