Files
Nicholas Carrigan (he/him) 3da4be21bb chore: seed chinese traditional (#42005)
Seeds the chinese traditional files manually so we can deploy to
staging.
2021-05-05 22:43:49 +05:30

1.4 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7b8c367417b2b2512b58 用 export default 創建一個默認導出 1 301199 create-an-export-fallback-with-export-default

--description--

export 的課程中,你學習了命名導出語法, 這可以在其他文件中引用一些函數或者變量。

還需要了解另外一種被稱爲默認導出export 的語法。 在文件中只有一個值需要導出的時候,通常會使用這種語法。 它也常常用於給文件或者模塊創建返回值。

下面是使用 export default 的例子:

export default function add(x, y) {
  return x + y;
}

export default function(x, y) {
  return x + y;
}

第一個是命名函數,第二個是匿名函數。

export default 用於爲模塊或文件聲明一個返回值,在每個文件或者模塊中應當只默認導出一個值。 此外,你不能將 export defaultvarletconst 同時使用。

--instructions--

下面的函數應該在這個模塊中返回一個值。 請添加需要的代碼。

--hints--

正確地使用 export 返回值。

assert(
  code.match(
    /export\s+default\s+function(\s+subtract\s*|\s*)\(\s*x,\s*y\s*\)\s*{/g
  )
);

--seed--

--seed-contents--

function subtract(x, y) {
  return x - y;
}

--solutions--

export default function subtract(x, y) {
  return x - y;
}