Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to export Arrow functions in ES6/7?

People also ask

Can you export an arrow function?

To export arrow functions in JavaScript, we can use export directly with arrow functions. const hello = () => console. log("hello"); export default hello; to export the hello function as a default export with export default .

When should you not use arrow functions in ES6?

An arrow function doesn't have its own this value and the arguments object. Therefore, you should not use it as an event handler, a method of an object literal, a prototype method, or when you have a function that uses the arguments object.

Are arrow functions ES6?

Introduction. The 2015 edition of the ECMAScript specification (ES6) added arrow function expressions to the JavaScript language. Arrow functions are a new way to write anonymous function expressions, and are similar to lambda functions in some other programming languages, such as Python.

Is arrow function ES5 or ES6?

The arrow function concept was introduced in ES6. With the help of this, we can write a shorter and concise syntax for a normal function which we used to write in ES5.


Is it possible to export Arrow functions in ES6/7?

Yes. export doesn't care about the value you want to export.

The export statement below gives a syntax error ... why?

You cannot have a default export and give it a name ("default" is already the name of the export).

Either do

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

or

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

If you don't want a default export, you can simply export a named function with this syntax:

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

Try this

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

or

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