Find your content:

Search form

You are here

Difference between import vs import {} in nodejs (Javascript)

 
Share

You could specify two types of module export in module file.

 

export default method1() {...}
export method2() {...}
export method3() {...}
When importing from above library
To import method1 we should write
Import x from "lib"; // default import is method1
Import {method3} from "lib"; // only method3 is imported
 
Import * as methods from "lib"; 
// you get 
Methods = {method2, method3, default: {method1}}
 
If there is no default export
Export method1(){}
Export method2(){}
Export method3(){}
 
Import methods from 'lib'; // undefined
Import {method3} from 'lib'; // it works
Import * as methods from 'lib'; // which has {method1, method2, method3}

 

My Block Status

My Block Content