CoverT 11: Function Properties

codeInteractive Code Example

Functions are just objects in Javascript, which means that they can have properties just like any other object.

Having properties on a function can be useful if you want to make your function configurable, or if you want a static propery for your function. This can be a nice alternative to creating a class or a wrapper object to maintain properties.

Example

sayHello.firstName = 'Chris';
console.log(sayHello()); // "Hello Chris"

function sayHello() {
  return `Hello ${sayHello.firstName}`;
}