JavaScript Modules Importing named members from another module

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Given that the module from the Defining a Module section exists in the file test.js, you can import from that module and use its exported members:

import {doSomething, MyClass, PI} from './test'

doSomething()

const mine = new MyClass()
mine.test()

console.log(PI)

The somethingPrivate() method was not exported from the test module, so attempting to import it will fail:

import {somethingPrivate} from './test'

somethingPrivate()


Got any JavaScript Question?