LoginSignup
3
0

More than 5 years have passed since last update.

ES6のimportとexport

Last updated at Posted at 2019-03-27
myModule.js
const message = 'some message'
const name = 'Hugo'
const location = 'Tokyo'
const getGreeting = name => {
    return `welcome ${name}`
}

export { message, name, getGreeting, location as default }   
index.js
import myCurrentLocation, { message, name, getGreeting } from './myModule';
console.log(myCurrentLocation);  // Tokyo
console.log(message, name);      // some message Hugo
console.log(getGreeting(name));  // welcome Hugo

・Named export  ⇒  import先で名前を変えられない(変えられました)
・Default export  ⇒  import先で名前を変えられる

3
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0