How to chain functions in JavaScript

Here’s a question you’ll sometimes encounter in interviews: How do you write a chaining function similar to jQuery in JavaScript?

The benefit is that we can mutate the same element with several method calls. The key detail is that each method call must return an object with methods we can call.

Here’s how you do it:

How to write a chaining function. Live code at https://codesandbox.io/embed/4w2n68n4w0

That’s it.