Modules Module #29 Flashcards

1
Q

How is imported module syntax represented

A

import package from ‘module-name’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the definition of a JavaScript Module?

A

A module is a JavaScript file that exports one or more values (objects, functions or variables), using the export keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What gets exported when running export default?

A

An anonymous function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can a module be imported into HTML?

A

Script tag with type= module as below

Note: this module import behaves like a defer script load. See efficiently load JavaScript with defer and async

It’s important to note that any script loaded with type=”module” is loaded in strict mode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s the advantage of using export default on scripts that you plan on importing into HTML?

A

Once the script is loaded you can name it whatever you like and use it in a different JS script

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you import a React file?

A

You can import the default export, and any non-default export by name, like in this common React import:

import React, { Component } from ‘react’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you rename a module on import?

A

import { someModule, anotherModule as newlyNamed} from ‘module-name’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are modules exported?

A

export default functionName

example: export default str => str.toUpperCase( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

absolute paths are supported for imports

A

import toUpperCase from ‘https://flavio-es-modules-example.glitch.me/uppercase.js’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

relative paths are also supported

A

import { toUpperCase } from ‘/uppercase.js’
import { toUpperCase } from ‘../uppercase.js’

Always begin the path with a / or ../ THATS NORMAL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How are multiple functions exported?

A
Call their names. Example:
const a = 1
const b = 2
const c = 3

export { a, b, c }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does a module import multiple modules

A

Using the universal selector * as such:

import * from ‘module-name’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly