Module 3 Flashcards
What is Array.prototype.filter useful for?
to filter data from an array and assign it to a new array
loops through the array and checks for truthies and falsies
What is Array.prototype.map useful for?
for data transformations
can transform data and create a new array for that
loops through the array and the return value of each iteration is pushed to new array
What is “syntactic sugar”?
syntax within a programming language that is designed to make things easier to read or to express. It makes the language “sweeter” for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.
What is the typeof an ES6 class?
function
Describe ES6 class syntax.
class Person { constructor(name) { this.name = name; } getName() { return this.name; } } Code language: JavaScript (javascript)'
use the class keyword with name and convention to start with uppercase letter and then everything lives inside the class block including your constructor method and any other method definitions
What is “refactoring”?
rewriting code to make it more beautiful /readable
not changing any of the functionality
What is Array.prototype.reduce useful for?
takes an array and reduces it down to a single value
taking values of an array and turning it into an object
What is Webpack?
Webpack is a free and open-source module bundler for JavaScript lets us write modules and supports any module formats because it helps us to bundle many js files into 1 js file
How do you add a devDependency to a package?
npm install some-package –save-dev (can also put the package name at the end)
npm i -D some-package (= shortcut)
i short for install, D short for save dev
What is an NPM script?
The “scripts” property of your package.json file that can be executed by running npm run-script or npm run for short.
How do you execute Webpack with npm run?
ensuring to include “build”: “webpack” in your NPM script
execute whatever script executes webpack
How are ES Modules different from CommonJS modules?
SYNTAX is easier to read with import/exporting
(import statements vs require statements)
Their syntax is even more compact than CommonJS’s.
Their structure can be statically analyzed (for static checking, optimization, etc.).
Their support for cyclic dependencies is better than CommonJS’s.
CommonJS is built in node js and designed for synchronous loading
What kind of modules can Webpack support?
- ECMAScript modules
- CommonJS modules
- AMD modules
supports BOTH ES modules and CommonJS modules
stick with require statements in node & import statements in front end code
What is React?
a JS library for building interfaces
that is declarative and component-based
What is a React element?
it’s a symbol?
Symbol(react.element)
they are immutable
How do you mount a React element to the DOM?
create a root by using ReactDOM.createRoot(container) & assigning that value to a root variable
and then root.render(element)
What is Babel?
a solution for allowing browsers to use complex / modern JS that is not fully supported across various browsers (JSX, typescript)
its a JS compiler built on a plug in system that parses JS syntax into an abstract syntax tree and rewrites it into a version that can be interpreted by your browser
Js compiler that takes ES6 and converts it to ES5
What is a Plug-in?
a plug-in is a software component that adds a specific feature to an existing computer program. When a program supports plug-ins, it enables customization
Babels plug-ins are needed to do anything
presets are dynamic bundles based on years
there is a preset for react
What is a Webpack loader?
allows you to pre-process your files
How can you make Babel and Webpack work together?
….
What is a React component?
returns a react element
How do you define a function component in React?
like a function that accepts single “props” object argument and it returns a react element
How do you mount a component to the DOM?
call the component
What is a React component?
describes a reusable piece of the UI