Software Development

JavaScript Self-Executing Anonymous Functions

This post demonstrates how to create SEAFs (Self-Executing Functions) in JavaScript and briefly shows how AngularJS applications heavily use this type of function.

Software Environment


  • Windows 10
  • Notepad or Notepad++
  • AngularJS 1.6.x
  • Plunker –

Self-Executing Anonymous Functions

An AngularJS application uses a lot of SEAFs (Self-Executing Functions).  When you reference an .js file in your main .html, most likely your .js codes are enclosed within a SEAF.


What are SEAFs then? These are functions that are defined and executed at the same time (when referenced). All codes withing an SEAF are then executed.

Defining and Executing an SEAF

An SEAF is a JavaScript code with the following syntax

Take these referenced .js files that are part of  an AngularJS project.


These files have codes within  SEAFs.




Plain SEAF JavaScript

You may check out the sample created at Plunker –



You Might Also Like