What is a module file fallback value?

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

export default function subtract(x, y) {
return x - y;
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36

Challenge: Create an Export Fallback with export default

Link to the challenge:

That’s what would be imported in case the import name you use is not in the named exports. So the “default import” is considered a fallback.

1 Like

before i answer your question, you should know the lessons regarding import/export will only be useful to you and more comprehensible, once you actually create a project wich consists of number of files and you need to import/export your code.
The default export, which is also used as a fallback, is what you will import from the file, if you dont point to a specific variable of its exported ones. For example i can create a file which consists of an apple object, a banana object and peach object and i make those objects available for import(export them) and also define a default export object called “fruit”. Whenever i wanna import one of the objects i can say “import the banana object” or “import the apple object” and gain access to it, from another file. But if i dont have a specific object in mind, i can just say “import whats in the fruits file” and ill get access to the default export, which is the “fruit” object. Ofc, the slang i used will be replaced with the proper codding syntax.

fruits.js:

let apple={
  color: 'red',
  taste: 'sweet'
}
let banana={ ... }
let peach={ ... }

const fruit={
  'list of fruits': [apple, banana, preach]
}

export apple
export default fruit

anotherFile.js:

import {apple} from './fruits.js'
import defaultFruit from './fruits.js'

console.log(apple)  /* { color: "red", taste: "sweet" } */
console.log(defaultFruit)  /* { 'list of fruits': [appleObj, bananaObj...] } */

*note there are different ways to export/import

1 Like

thanks a lot, helped so much

now I get it. thanks