Modules in JavaScript
Modules are a way to organize and share code in JavaScript. Modules allow you to define variables and functions in one file and use them in another file.
Here's an example of how to use modules in JavaScript:
// file1.js
export const name = 'John';
export function sayHello() {
console.log(`Hello, my name is ${name}.`);
}
// file2.js
import { name, sayHello } from './file1.js';
console.log(name); // prints "John"
sayHello(); // prints "Hello, my name is John."
No comments:
Post a Comment