capitalizeFirstLetter
, that simply takes in a string and returns the string with the first letter capitalized. You want to use this function in several different javascript files. In order to share the function with the files, you need to first export
it.
```js
export const capitalizeFirstLetter = (string) => {
return string.charAt(0).toUpperCase() + string.slice(1);
}
```
The above is a common way to export a single function, but you can achieve the same thing like this:
```js
const capitalizeFirstLetter = (string) => {
return string.charAt(0).toUpperCase() + string.slice(1);
}
export { capitalizeFirstLetter };
```
After you export a function like this, you can import it in another file to use without having to rewrite the function.
foo
is exported.
testString: getUserInput => assert(getUserInput('index').match(/export\s+const\s+foo\s*=\s*"bar"/g), 'foo
is exported.');
- text: bar
is exported.
testString: getUserInput => assert(getUserInput('index').match(/export\s+const\s+bar\s*=\s*"foo"/g), 'bar
is exported.');
```