3.2 Building with JavaScript Flashcards

1
Q

If you decide to use SCSS because CSS is missing some features, what do you need to be aware of?

A

As browsers don’t know how to read SCSS, you’d need to transform any SCSS you write into CSS before deploying your app.

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

What is the “build process?”

A

There are a number of tasks to complete during the development process that help with the organization, readability, and maintenance of your code; however, these steps don’t always translate smoothly when it comes to executing your code. Thus, the need to process code has emerged, and this step is what’s known as the build process.

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

What are the main operations of the “build process”?

A

Transpilation: Some languages, or versions of languages, can’t be directly interpreted by the browser; transpiling fixes this by rewriting them in a way that the browser can understand.

Bundling files: Bundling files refers to regrouping code into a smaller number of files to improve an application’s performance in the browser.

Minification: Minification is the process of removing all unnecessary characters from a file in order to make the file as small as possible and faster to load.

Auto-prefixing CSS: Auto-prefixing is the process of automatically adding the correct prefixes to CSS syntax to make sure it can be understood by different browsers.

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

What are the benefits of using a build tool?

A

You can, of course, perform these operations manually by running the appropriate commands in the command line; however, in order to streamline the build process and develop at a faster pace, it’s better to roll them into a single step using a build tool (i.e., a single tool that will perform all of the operations at once with a single command).

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

What is transpilation? (Step 1 on the build process)

A

Transpilation involves transforming code written in one programming language into code written in another programming language. Sometimes, whatever’s going to be executing the code (i.e., the runtime environment) can’t read the code as-is, so this extra step is required to change the code into a language the processor can understand

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

Name one example of transplilation

A

One example of transpilation you’re likely to be familiar with is JavaScript’s ES6. You might remember from Achievement 2 that ES6, or ES2015, was finalized in June 2015 and made significant improvements to JavaScript—improvements that rendered many libraries obsolete. Prior to ES2015, developers needed a third party library to use promises; now, they’re supported natively. To this day, however, not all browsers fully support ES6 syntax, including a few mobile browsers and Internet Explorer. For this reason, ES6 has to be transpiled into ES5 JavaScript so that all browsers can understand it.

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

Name some examples of languages besides ES6 that require transpilation

A

There are a number of other languages besides ES6 that require transpilation: JSX, a React-based syntax that allows HTML and XML to cohabit with JavaScript code, must be transpiled into JavaScript; TypeScript must be transpiled into JavaScript; and SCSS must be transpiled into CSS, to name a few.

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

JavaScript development is, by necessity, modularized.

What are some of the disadvantages of that?

A

JavaScript development is, by necessity, modularized. A project will contain numerous files with varying responsibilities and dependencies.

Here’s an example:

// sum.js
export default function sum(a, b) {
  return a + b;
}

And in another file:

// index.js
import sum from './sum';
sum(1, 2);

There are two problems associated with this approach: 1) browsers don’t know how to deal with modularized code (they only load what they’re specifically instructed to load), and 2) additional queries take time. This is where bundling comes in useful.

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

What does “bundling files” mean?

A

Bundling files means grouping them into as few files as possible. This is usually done by way of a build tool. The build tool looks at an “entry file” within the project (“index.js” in the example above), then determines what that file requires to run (what its dependencies are) and concatenates the two (or more) files into a single, new file called the “bundle file,” “build file,” or “output.”

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

Why is id better to use a build tool to bundle files?

A

Though bundling can be done manually, using a build tool brings one significant advantage: the build tool will first construct a dependency tree that maps the dependencies of the entire project, and only then will it bundle the files. This generally makes the final file more optimized as it won’t make the mistake of adding the same dependency twice.

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

What is “minification”? (Step 3 in the build process)

A

Minification is the process of removing data that’s not needed by the browser from a code file and simplifying the code as much as possible. For example, additional spaces and code comments are removed, and variable names are replaced with single letters.

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

What is “auto-prefixing”? (Step 4 of the build process)

A

Non-standard or experimental CSS features often need to be “prefixed” by the browsers displaying them before said browsers can fully support them. In order to write CSS code that’ll be properly interpreted, even on old browsers, you have to write both the regular rule (e.g., display: flex;) and the prefixed version . To make matters more complicated, you also need one prefix per browser vendor.

display: -webkit-box;
display: -ms-flexbox;
display: flex;
As you can probably imagine, auto-prefixing is a tedious and error-prone task when done manually. For this reason, it’s often automated and handled by a build tool as part of the build process.

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

Why is the build process and using a build tool so important?

A

The build process usually marks the first step at the beginning of a new project. Setting up your build tool early on means you can develop and implement features incrementally and iteratively by immediately viewing the end result in your browser.

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

What are the benefits of using Parcel as a build tool?

A

arcel requires minimal configuration, has fast bundle times, is well-documented and actively maintained, and works automatically with a variety of files. It also offers some very useful features such as building and serving your code, and refreshing the browser every time the code changes.

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

How does Parcel work?

A

How it works is easy: you tell Parcel which file in your project is the entry file (usually “index.html”); then, Parcel bundles all the files contained within that file into a single file before serving it back, ready to be viewed in a browser.

What happens behind the scenes is also pretty straightforward: Parcel takes an entry file, lists all of its dependencies (and any dependencies of those dependencies), then builds a dependency tree of all the files that depend on each other. For each of the mapped files, Parcel detects their format and performs the necessary build operations on them (e.g., transpiling and/or minifying). As a final step, Parcel bundles everything into as few files as possible.

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

What does “live reloading code” mean?

A

As you just learned above, Parcel builds your code, serves it, and refreshes the browser every time your code changes. This important step in the development process is known as live reloading. What this means in practice is that each time you make a change to your code, the build system automatically triggers a page refresh in your browser. This can dramatically increase your development speed as you no longer need to switch back and forth between your code editor and your browser—the latter is updated automatically.

17
Q

Which browsers are recommended to use then working with React?

A

When working with React, we highly recommend that you use either Chrome or Firefox. It will simply make your life easier as a developer!

18
Q

What is development mode and production mode in Parcel referring to?

A

In development mode, Parcel only transpiles and bundles your code.

If you were in production mode, it would minify your code, too.

19
Q

What’s the difference between dependencies and development dependencies?

A

It’s essential that you install the correct dependencies for your project. This includes dependencies and development dependencies. As a recap, dependencies are what your application needs for both development and production, while development dependencies are only necessary during development.

20
Q

What is the file structure in the client folder when working with React?

A

Rather than the classic “index.html” > “index.css” structure, here you have “index.html” > “index.jsx” > “index.scss inside a folder called “src” that is located within the folder “client”