A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829 below:

JavaScript ‪Module Cheatsheet 📄‬ | by Samantha Ming | DailyJS

JavaScript ‪Module Cheatsheet 📄‬ 4 min read

·

Nov 18, 2019
Press enter or click to view image in full size Code Tidbit by SamanthaMing.com

Here’s a cheatsheet to show you the different ways of exporting and the corresponding way to import it. It really distills to 3 types: name, default, and list. Just make sure your export matches your import way and you will have no problem 👍

// Name Export | Name Import
export const name = 'value'
import { name } from '...'
// Default Export | Default Import
export default 'value'
import anyName from '...'
// Rename Export | NameImport
export { name as newName }
import { newName } from '...'
// Name + Default | Import All
export const name = 'value'
export default 'value'
import * as anyName from '...'
// Export List + Rename | Import List + Rename
export {
name1,
name2 as newName2
}
import {
name1 as newName1,
newName2
} from '...'

Now let’s look at each of them and see how they work 🤓

a. Name

The key here is having a name. Hence a “named” export lol 😂

export const name = 'value';import { name } from '...';console.log(name); // 'value'

❌ What did I say, no name, no export!

export 'value'
import { } // 👈 see I don't even know what to put…

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4