In the world of Javascript, functions are not just simple entities but rather objects with various capabilities. They can be assigned to variables, executed by calling them, and even have properties assigned to them or read from them.
For instance, let's take a look at this example where we assign the module.exports from the 'express' module to a variable named 'express':
const express = require('express');
Now, here's how you would execute the function by calling it:
const app = express();
And finally, accessing the .static property on the express function would look like this:
app.use(express.static('/public'));
Another interesting aspect is that all regular functions come with some built-in properties. For example, considering a function greet(greeting) which prints out the greeting:
function greet(greeting) {
console.log(greeting);
}
// This will output 1 as the function has one declared argument
console.log(greet.length);
Furthermore, you also have the flexibility to add your own custom properties to functions, thanks to their nature as a sub-class of an object.