JAVASCRIPT-DEVELOPER-I practice question 6 of 30

A developer has an ErrorHandler module that contains multiple functions. What kind of export should be leveraged so that multiple functions can be used?

Full set: 219 questions

Domain Objects, Functions, and Classes

Answer options
A: all
B: named Correct answer
C: multi
D: default
Correct Answer:
B. named
Explanation

In JavaScript ES6 modules, which are fundamental to Lightning Web Components, there are two types of exports: named and default. A module can have multiple named exports but only one default export. To make multiple functions from a single module (like ErrorHandler) available for other modules to import and use, named exports must be used. Each function is exported using the export keyword followed by its declaration, and imported using its specific name within curly braces {}.

Why Incorrect

A. all: export all is not a valid JavaScript syntax for exporting multiple functions from the current module. The export from 'module' syntax is for re-exporting from another module.
C. multi: "multi" is not a recognized keyword or type of export in the JavaScript ES6 module system.
D. default: A module can only have one default export. This is typically used for the main or primary value of a module, not for exporting multiple, distinct functions.

References

1. Salesforce Lightning Web Components Developer Guide:

Section: Share JavaScript Code

Content: The documentation explicitly demonstrates using named export statements to share multiple utility functions from a JavaScript file. It states, "To import the functions, use the import statement with the function names in curly braces." This directly supports the use of named exports for multiple functions.

2. MDN Web Docs (Mozilla):

Page: export statement

Content: This is a canonical resource for the JavaScript language. It clearly defines and provides syntax for "Named exports" and "Default export." The documentation specifies, "Named exports are useful to export several values. During the import, one will be able to use the same name to refer to the corresponding value." This confirms that exporting "multiple functions" requires named exports.

3. ExploringJS by Dr. Axel Rauschmayer (Academic Resource):

Chapter: 17. Modules

Section: 17.3.1 Named exports (several per module)

Content: This text, often used in academic settings, explains, "You can have multiple named exports per module. A named export is created by prefixing a declaration with the keyword export." This academic source validates that the standard mechanism for exporting several items is the named export.

Scroll to Top