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 function.

Software Environment

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

Self-Executing Anonymous Functions

An AngularJS the 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 within an SEAF are then executed.

Defining and Executing a 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 –


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like