Skip to main content Accessibility Feedback

ES Modules

export

Use the export operator to export modules for use in other files.

One way to do that is by adding the export operator before the variable or function expression.

export function add (num1, num2) {
	return num1 + num2;
}

export function subtract (num1, num2) {
	return num1 - num2;
}

Alternatively, you can include an export at the end as a single line, with an object of exported variables and functions. You can use the object property shorthand approach for this.

function add (num1, num2) {
	return num1 + num2;
}

function subtract (num1, num2) {
	return num1 - num2;
}

export {add, subtract};

Join the Lean Web Club! Coaching. Courses. Coding resources. Get the skills, confidence, and support you need to learn front-end web development and achieve long-term success.


Find this useful? You can support my work by purchasing an annual membership.