Destructure a named export from a simulated module.
Acceptance criteria
- 1.#out should show 10.
JavaScript Tutorial · JavaScript Modules
These 10 tasks go with the JavaScript import chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “import brings an exported value from another module into the current file.” .
1.Import a named valueexercise · easy · 10 min
Destructure a named export from a simulated module.
Passes when: #out should show 10.
2.Import and renameexercise · easy · 10 min · practice plan
Destructure a value under a different local name.
Passes when: #out should show 14.
3.Import a default exportexercise · easy · 10 min · practice plan
Read a default export under a local name of your choice.
Passes when: #out should show 28.
4.Import everything as a namespaceexercise · easy · 10 min · practice plan
Import a whole module as one object and use two of its exports.
Passes when: #out should show 16 and 28.
5.Import default and named togetherexercise · medium · 10 min · practice plan
Read both the default and a named export from one module.
Passes when: #out should show 28 and 16.
6.Fix the wrong name importedbug fix · easy · 8 min
The destructured name does not match what the module exported.
Passes when: #out should show 10.
7.Fix the default imported with bracesbug fix · easy · 8 min · practice plan
A default export is imported without curly braces.
Passes when: #out should show 28.
8.Fix the rename applied to the wrong sidebug fix · easy · 8 min · practice plan
The local variable should be renamed, not the source property.
Passes when: #out should show 14.
9.Fix only one export importedbug fix · easy · 8 min · practice plan
Destructuring one name means the others are never brought into scope.
Passes when: #out should show 16 and 28.
10.Fix the default and named mixed upbug fix · easy · 8 min · practice plan
The default export and the named export were read from swapped keys.
Passes when: #out should show 28 and 16.
Between them these tasks cover Named imports, Default imports and import * as.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.