0

I was thinking that maybe the name "Immediately Invoked Function Expression" is incorrect, because, in fact, what we do is invoke an anonymous function declaration, so the correct name could be IIFD (Immediately Invoked Function Declaration).

What do you think? Make sense?

// function declaration
function add( a, b ) {
  return a + b;
}

// function expression
var multiply = function( a, b ) {
  return a * b;
}
Eric Douglas
  • 449
  • 7
  • 12
  • IINFE..!? (Immediately invoked *named* function expression...) – deceze May 13 '15 at 13:08
  • 1
    I also cast an IICVFBPOB (immediately invoked close vote for being primarily opinion based). – deceze May 13 '15 at 13:11
  • See [What is the difference between a function expression vs declaration in JavaScript?](http://stackoverflow.com/questions/1013385/what-is-the-difference-between-a-function-expression-vs-declaration-in-javascrip) – Qantas 94 Heavy May 13 '15 at 13:14
  • @deceze it's not opinion-based, it's wrong, so I guess you wanted to cast an IICVFBW. –  May 13 '15 at 13:19
  • @torazaburo I wish that actually existed! – deceze May 13 '15 at 13:20

2 Answers2

4

No.

A function declaration is a statement that starts with the keyword function. At any other point the keyword function is used, it defines a function expression. An IIFE looks like (function() {})() so the statement starts with (, not function, so it is a function expression.

erikkallen
  • 33,800
  • 13
  • 85
  • 120
1

what we do is invoke an anonymous function declaration

There is no such thing as an anonymous function declaration. Where did you hear of such a thing? Of what possible use would it be? It would be like a tree falling in the forest.

Try typing

function() { }

into your console and see what it says. In Chrome devtools I get

Uncaught SyntaxError: Unexpected token (

This is not even valid syntax.

Why did you imagine that IIFE's have the form

(                       // <== MARK AS FUNCTION EXPRESSION
    function() {...
    }()
)

The parentheses are precisely to make this treated as a function expression so it can be called.