Getting Started with ES6 Modules

  • In lists.js , I am exporting a head function that returns the first in the array.
  • Then in main.js , I am importing only the head function in, defining an array of words, and then logging the first word to the console by calling the head function.
  • /** * returns the first item in the array or undefined */ export function head(list) { if (!list || !list.length) { return undefined; } return list[0]; } /** * returns the last item in the array or undefined */ export function tail(list) { if (!list || !list.length) { return undefined; } return list[list.length – 1]; } /** * returns a copy of the list or empty */ export function copy(list) { if (!list || !

Read the full article, click here.


@notoriousb1t: “Getting Started With ES6 Modules: #JavaScript #webdevelopment”


The ES6 module feature is one of the most important changes to come to JavaScript in recent history. It has the power to transform an unwieldy mess of 10,000 lines into smaller bite sized pieces and only use the parts you really need.


Getting Started with ES6 Modules

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.