One of the weirdest JavaScript features: Functions can have properties


One of the weirdest JavaScript features: Functions can have properties.

Why? Because JavaScript functions are objects.

So, this is valid JS.

So when is this useful? When you want to assign metadata to a function.

One real-world example where this was useful: React used this JS feature to implement prop-types.

View original on X