Simulate a module exporting a function and a constant.
Acceptance criteria
- 1.#out should show 10 and 3.
JavaScript Tutorial · JavaScript Modules
These 10 tasks go with the JavaScript export 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: “export makes a function, variable or class available to other modules.” .
1.Export two named valuesexercise · easy · 10 min
Simulate a module exporting a function and a constant.
Passes when: #out should show 10 and 3.
2.Export a default valueexercise · easy · 10 min · practice plan
Simulate a default export and use it.
Passes when: #out should show 42.
3.Export a renamed valueexercise · easy · 10 min · practice plan
Export a function under a different public name.
Passes when: #out should show 6.
4.Export a list of functionsexercise · easy · 10 min · practice plan
Export two already-declared functions together.
Passes when: #out should show 5 and 3.
5.Combine named and defaultexercise · medium · 10 min · practice plan
Export both a default and a named value from the same module.
Passes when: #out should show 28 and 16.
6.Fix the export left off the objectbug fix · easy · 8 min
The function was declared but never added to the exports.
Passes when: #out should show 10.
7.Fix the default read as a named exportbug fix · easy · 8 min · practice plan
The default export is read from the default key, not by its function name.
Passes when: #out should show 42.
8.Fix the wrong name exportedbug fix · easy · 8 min · practice plan
The export list uses the wrong key for the renamed function.
Passes when: #out should show 6.
9.Fix only one function exportedbug fix · easy · 8 min · practice plan
Both functions were meant to be exported, not just one.
Passes when: #out should show 5 and 3.
10.Fix the default overwritten by a named exportbug fix · easy · 8 min · practice plan
The named export used the same key as the default, replacing it.
Passes when: #out should show 28 and 16.
Between them these tasks cover Named exports, Default export and Export lists.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.