2019-06-28 16:04:59 +08:00

1.5 KiB

id, title, challengeType
id title challengeType
587d7b8d367417b2b2512b59 Import a Default Export 1

Description

In the last challenge, you learned about export default and its uses. To import a default export, you need to use a different import syntax. In the following example, add is the default export of the math_functions.js file. Here is how to import it:
import add from "./math_functions.js";

The syntax differs in one key place. The imported value, add, is not surrounded by curly braces ({}). The primary method of importing a default export is to simply write the value's name after import.

Instructions

In the following code, import the default export, subtract, from the file math_functions.js, found in the same directory as this file.

Tests

tests:
  - text: You should properly import <code>subtract</code> from <code>math_functions.js</code>.
    testString: assert(code.match(/import\s+subtract\s+from\s+('|")\.\/math_functions\.js\1/g));

Challenge Seed

  
// add code above this line

subtract(7,4);

Solution

import subtract from "./math_functions.js";
// add code above this line

subtract(7,4);