12.
Examine the following JavaScript ES6 code:
// greet.js
export function sayHello(name) {
return `Hello, ${name}!`;
}
// app.js
import * as allGreetings from './greet.js';
console.log(allGreetings.sayHello('Sarah'));
What will the console statement output when running the app.js file in a Node.js environment?
Error: Cannot find module './greet.js'
greet.js
sayHello('Sarah')
Hello, Sarah!
Correct: D
The import * as syntax is used to import all exports from a module as an object, where their original names are used to reference individual exports. In this case allGreetings is an object that contains all exports from the greet.js module, including the sayHello function. When sayHello is called with 'Sarah' as an argument, it outputs Hello, Sarah!.