0
0
Javascriptprogramming~15 mins

Exporting values in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Exporting Values in JavaScript
📖 Scenario: You are building a small JavaScript module that holds some data and you want to share this data with other parts of your program.
🎯 Goal: Create a JavaScript module that exports a value, then import and use that value in another file.
📋 What You'll Learn
Create a variable with a specific value
Export the variable using export
Import the exported variable in another file
Print the imported value to the console
💡 Why This Matters
🌍 Real World
Exporting and importing values is how JavaScript modules share code and data in real projects.
💼 Career
Understanding exports and imports is essential for working with modern JavaScript frameworks and libraries.
Progress0 / 4 steps
1
Create a variable to export
Create a variable called greeting and set it to the string 'Hello, world!'.
Javascript
Need a hint?

Use const greeting = 'Hello, world!'; to create the variable.

2
Export the variable
Add a line to export the variable greeting using the export keyword.
Javascript
Need a hint?

Use export { greeting }; to export the variable.

3
Import the exported variable
In a new file, write an import statement to import greeting from the module file named './greetings.js'.
Javascript
Need a hint?

Use import { greeting } from './greetings.js'; to import the variable.

4
Print the imported value
Write a line to print the imported greeting variable to the console using console.log.
Javascript
Need a hint?

Use console.log(greeting); to print the value.