export default as from code example

Example 1: export and export default

// Three different export styles
export foo;
export default foo;
export = foo;

// The three matching import styles
import {foo} from 'blah';
import foo from 'blah';
import * as foo from 'blah';

Example 2: export default react

import React from 'react'; // get the React object from the react module

class HelloWorld extends React.Component {
  render() {
    return <p>Hello, world!</p>;
  }
}

export default HelloWorld; // expose the HelloWorld component to other modules

Example 3: export default

/*
Since export default is used to declare a fallback value for a module or 
file, you can only have one value be a default export in each module or 
file. Additionally, you cannot use export default with var, let, or const.
*/

// named function
export default function add(x, y) {
  return x + y;
}

// anonymous function
export default function(x, y) {
  return x + y;
}

Example 4: javascript export default

// Exporting individual features
export let name1, name2,, nameN; // also var, const
export let name1 =, name2 =,, nameN; // also var, const
export function functionName(){...}
export class ClassName {...}

// Export list
export { name1, name2,, nameN };

// Renaming exports
export { variable1 as name1, variable2 as name2,, nameN };

// Exporting destructured assignments with renaming
export const { name1, name2: bar } = o;

// Default exports
export default expression;
export default function () {} // also class, function*
export default function name1() {} // also class, function*
export { name1 as default,};

// Aggregating modules
export * from; // does not set the default export
export * as name1 from;
export { name1, name2,, nameN } from;
export { import1 as name1, import2 as name2,, nameN } from;
export { default } from;