In the last challenge, you learned about
export default
and its uses. It is important to note that, toimport
a default export, you need to use a differentimport
syntax.
In the following example, we have a function,
add
, that is the default export of a file,"math_functions"
. Here is how toimport
it:
import add from "math_functions";
add(5,4); //Will return 9
The syntax differs in one key place-the imported value,
add
, is not surrounded by curly braces,{}
. Unlike exported values, the primary method if importing a default export is to simply write the value's name afterimport
.
In the following code, please
import
the default export,subtract
, from the file"math_functions"
, found in the same directory as this file.
subtract(7,4);
assert(code.match(/import\s+subtract\s+from\s+"math_functions"/ig))
import subtract from "math_functions";
subtract(7,4);