Example 1 — Export list
export { name } at the bottom.
JavaScript
const x = 1; export { x }; console.log(x); How It Works
- Declares then exports.
Use export to share values from a module file. Named exports use braces at import time; a module may also have one export default.
// Imagine math.js
export const PI = 3.14;
export function area(r) { return PI * r * r; }
console.log(area(1).toFixed(2)); export { name } at the bottom.
const x = 1; export { x }; console.log(x); export { x as y }.
const x = 2; export { x as y }; console.log(x); One default per module.
export default function main(){ return 1; }
console.log(main()); CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful