JS Interview Question: What’s a typical use case for anonymous functions?

What’s a typical use case for anonymous functions?

RLyn Ben
1 min readJan 12, 2016


Since Anonymous Functions are function expressions rather than the regular function declaration which are statements. Function expressions are more flexible. We can assign functions to variables, object properties, pass them as arguments to other functions, and even write a simple one line code enclosed in an anonymous functions.


var squaredArray = inputArray.map(function(x) { return x * x; });

With ES6 syntax this becomes even more concise.

var squaredArray = inputArray.map(x => x * x);

Another typical example would be an anonymous function used by popular frameworks used as IIFE (Immediate Invoked Function Expression).

(function() { })();


If you are looking for a platform to develop your clients’ website, check out my SAAS platform https://ecompurpl.com :)

EcomPurpl.com is the all-in-one solution for anyone looking to create a website. Templates, E-Commerce, Hosting, Galleries, Booking & Appointments, CRM, 24/7 support, and integration of your app are all included.



RLyn Ben

Software Engineer / Front-End Dev. Currently resides in Las Vegas. https://ecompurpl.com