Categories
JavaScript Answers

How to export arrow functions in JavaScript?

Spread the love

Sometimes, we want to export arrow functions in JavaScript.

In this article, we’ll look at how to export arrow functions in JavaScript.

How to export arrow functions in JavaScript?

To export arrow functions in JavaScript, we can use export directly with arrow functions.

For instance, we write

const hello = () => console.log("hello");
export default hello;

to export the hello function as a default export with export default.

We can also write

export const hello = () => console.log("hello");

to export hello as a named export.

Conclusion

To export arrow functions in JavaScript, we can use export directly with arrow functions.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *