npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

javascript-lab

v1.0.0

Published

A JavaScript lab

Readme

JavaScript Functions as First Class Data: Array of Functions

Learning Goals

  • Create a JavaScript function that loops through a function Array

Introduction

Since functions in JavaScript are "first-class" objects, it means they can be treated like any other data type in JavaScript (Number, String, et al.). A fun way to experience this truth is to load up an Array of Functions and then call each Function.

Create a JavaScript Function That Loops Through a Function Array

Let's create an Array of dog-care functions so that we can report on the activities we take in caring for Byron the Poodle.

When this program runs, it should print out:

console.log("Wake Byron the poodle");
console.log("Leash Byron the poodle");
console.log("Walk to the park with Byron the poodle");
console.log("Throw the frisbee for Byron the poodle");
console.log("Walk home with Byron the poodle");
console.log("Unleash Byron the poodle");

Start by creating a function for every activity that you see listed above:

For example:

function wakeDog() {
  console.log("Wake Byron the poodle");
}
...

But wait, if we write it in this way, all of our uses of this function will be for Byron the poodle. Let's generalize now and make each function take a dogName and dogBreed parameter. Thus:

function wakeDog(dogName, dogBreed) {
  console.log(`Wake ${dogName} the ${dogBreed}`);
}
...

Additionally: Each function should return the string that it creates. That is, we should create a String, log it to the console (using console.log()), and return that String.

Create the Array o' Functions

Continue writing "generalized" functions for

  • wakeDog
  • leashDog
  • walkToPark
  • throwFrisbee
  • walkHome
  • unleashDog

Each function's implementation will be a generalized invocation of console.log().

Create the Array o' Functions

Next, create our "Array o' Functions!" Create a variable called routine. This variable will be an Array all of the functions we've just defined.

Create a Function to Process the Array o' Functions

Lastly, create the function called exerciseDog that will take in two arguments:

  • dogName
  • dogBreed

The function's implementation should

  • Iterate over the routine Array
  • Call each function in the array and
  • pass the dogName and dogBreed received by exerciseDog() to the function as they are called
  • capture the result of each function's call
  • return an Array of all those functions' return values

Conclusion

This lab demonstrates the power of Functions as first-class data. We can stack them up in Arrays or assign them inside of Objects or save them to variables, or iterate over them. Instead of merely having Arrays of Strings and other familiar items, we can stuff them with work. And that's nothing short of amazing!

First Class Functions MDN