JavaScript Flashcards
What is the purpose of variables?
store date for later use with a name
How do you declare a variable?
keyword var
How do you initialize (assign a value to) a variable?
= sign
What characters are allowed in variable names?
_$@#1 and letters, cant start with #
What does it mean to say that variable names are “case sensitive”?
needs consistency with uppercase/lowercase
What is the purpose of a string?
hold letters/characters
What is the purpose of a number?
hold numeric values
What is the purpose of a boolean?
logical value true/false
What does the = operator mean in JavaScript?
assign value
How do you update the value of a variable?
assign it a new value
What is the difference between null and undefined?
null is intentional and is assigned/ undefined is not intentional and is not assigned
Why is it a good habit to include “labels” when you log values to the browser console?
so you know what output is for what console log
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined, symbol, bigint
What data type is returned by an arithmetic operation?
number
What data type is returned by an arithmetic operation?
number
What is string concatenation?
joining/combining 2 strings together for a new string
What purpose(s) does the + plus operator serve in JavaScript?
adding 2 values or concatenating
What data type is returned by comparing two values (, ===, etc)?
boolean T/F
What does the += “plus-equals” operator do?
addition assignment, adds additional info to variable to add to
What are objects used for?
grouping together variables and functions
What are object properties?
additional information for the object, name/value, individual keys in an objects
Describe object literal notation.
var object = { # = 1 } declare variable and assign property/value
How do you remove a property from an object?
using delete operator then dot notation for object.property
What are the two ways to get or update the value of a property?
bracket notation, dot notation
What are arrays used for?
store a list of values that are related
Describe array literal notation.
var name = [ ]
How are arrays different from “plain” objects?
hold different amounts of information,
arrays don’t need individual keys
arrays have length property and important to know amount
object not important to know number
What number represents the first index of an array?
[0]
What is the length property of an array?
number of items in an array
How do you calculate the last index of an array?
using the length property then subtracting one
What is a function in JavaScript?
a set of statements to perform tasks with related inputs and outputs and reuseable
are objects
Describe the parts of a function definition.
The function keyword to begin the creation of a new function.
An optional name.
A comma-separated list of zero or more parameters, surrounded by () parentheses.
The start of the function’s code block, as indicated by an { opening curly brace.
An optional return statement.
The end of the function’s code block, as indicated by a } closing curly brace.
a set of inputs, a set of outputs, and a rule that relates the elements
Describe the parts of a function call.
The function’s name.
A comma-separated list of zero or more arguments surrounded by () parentheses.
Our sayHello function does not take any arguments.
When comparing them side-by-side, what are the differences between a function call and a function definition?
definition doesn't return anything but calling the function does code block function keyword
What is the difference between a parameter and an argument?
parameter is a placeholder
argument is the value
recipe vs ingredients
Why are function parameters useful?
to give the function values, varying results
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value we can use in our program.
Prevents any more code in the function’s code block from being run.
Why do we log things to the console?
to check the result of the code and to make sure everything is working
What is a method?
In JavaScript functions themselves are objects, so, in that context, a method is actually an object reference to a function. A method is a function which is a property of an object. function stored in a property
How is a method different from any other function?
a method is associated with an object property, while a function is not.
How do you remove the last element from an array?
pop( )
How do you round a number down to the nearest integer?
math. floor ( )
How do you generate a random number?
math.random
random method
How do you delete an element from an array?
splice ( )
splice(start, deleteCount)
How do you append an element to an array?
push–end
unshift-beginner
How do you break a string up into an array?
split ( )
Do string methods change the original string? How would you check if you weren’t sure?
no, you can log it
strings are immutable
Roughly how many string methods are there according to the MDN Web docs?
over 40
Is the return value of a function or method useful in every situation?
no if there are additional methods/functions after
Roughly how many array methods are there according to the MDN Web docs?
over 40
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
=, ===, !=, >=, <=, ==
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
evaluates a condition
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if keyword
( ) arguments
{ } code block
What are the three logical operators?
&& logical and
|| or
! not
How do you compare two different expressions in the same condition?
use the logical operator
What is the purpose of a loop?
a sequence of instructions that is continually repeated until a certain condition is met in computer programming
repeat a block of code automatically
What is the purpose of a condition expression in a loop?
to see if the loop should run
What does “iteration” mean in the context of loops?
a process wherein a set of instructions or structures are repeated in a sequence a specified number of times or until a condition is met.
set of expressions
Means how many times the loop will loop.
When does the condition expression of a while loop get evaluated?
before each iteration
When does the initialization expression of a for loop get evaluated?
once before the loop begins
When does the condition expression of a for loop get evaluated?
before the iteration after initialization
When does the final expression of a for loop get evaluated?
at the end of every iteration
before the next evaluation of condition
after code block runs
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
What does the ++ increment operator do?
adds one to the operand
and reassigns
substitutes value
How do you iterate through the keys of an object?
for … in loop statement
What object is passed into an event listener callback when the event fires?
the target object/element
Why do we log things to the console?
check functionality and remove potential bugs
What is a “model”?
representation of something
Which “document” is being referred to in the phrase Document Object Model?
the HTML document
What is the word “object” referring to in the phrase Document Object Model?
the elements
the data type object
What is a DOM Tree?
a model of the webpage
connects parent elements and children nodes
Give two examples of document methods that retrieve a single element from the DOM.
get elements by id
*query selector
Give one example of a document method that retrieves multiple elements from the DOM at once.
query selector all
Why might you want to assign the return value of a DOM query to a variable?
to make it easier for the browser to look for
What console method allows you to inspect the properties of a DOM element object?
console.dir( )
directory
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
Because the browser needs to go through all the HTML elements before the JavaScript code can access it.
What does document.querySelector() take as its argument and what does it return?
the css selector
* The first element within the document that matches the selector or null
What does document.querySelectorAll() take as its argument and what does it return?
A css selector (universal, type, class, id or attribute) and it returns a Node List with all the properties of that selector.
Why do we log things to the console?
to check functionality
What is the purpose of events and event handling?
for user interactions
Are all possible parameters required to use a JavaScript method or function?
no, there are functions with no parameters
optional parameters
What method of element objects lets you set up a function to be called when a specific type of event occurs?
add event listener ( )
What is a callback function?
A function that takes another function as parameter and is not called by us. function definition being passed around with value
What object is passed into an event listener callback when the event fires?
the event object
all the data of the event that occurred
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
It is the elements that was interacted with. MDN.
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick( ))
first is a callback function
second is just a separate function
What is the className property of element objects?
Property of DOM element that gets and sets the className of an element.
How do you update the CSS class attribute of an element using JavaScript?
using the class name var cName = elementNodeReference.className; elementNodeReference.className = cName;
What is the textContent property of element objects?
Property that gets and sets the text content of an element and child
How do you update the CSS class attribute of an element using JavaScript?
query the class
How do you update the text within an element using JavaScript?
query the element
text content property
Is the event parameter of an event listener callback always useful?
no, it is not always used
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
a lot more complicated
Why is storing information about a program in variables better than only storing it in the DOM?
Because storing DOM locations in a variable prevents the browser from looking for the information.
easier for javascript to work with
What event is fired when a user places their cursor in a form control?
focus
What event is fired when a user’s cursor leaves a form control?
blur
What event is fired as a user changes the value of a form control?
input
What event is fired when a user clicks the “submit” button within a ?
submit
What does the event.preventDefault() method do?
It prevents the default event functionality from being fired from happening.
What does submitting a form without event.preventDefault() do?
automatically reloads the form
What property of a form element object contains all of the form’s controls.
.elements property
What property of a form control object gets and sets its value?
.value property
What is one risk of writing a lot of code without checking to see if it works so far?
there could be bugs that could have been prevented
What is an advantage of having your console open when writing a JavaScript program?
debugging
seeing events
Does the document.createElement( ) method insert a new element into the page?
no
How do you add an element as a child to another element?
. appendChild ( )
What do you pass as the arguments to the element.setAttribute( ) method?
the attribute name and attribute value
What steps do you need to take in order to insert a new element into the page?
create the element then append the element to the document
What is the textContent property of an element object for?
Property thats gets and sets the text content of an element.
Name two ways to set the class attribute of a DOM element.
set Attribute ( ) className method
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
automation and so you don’t repeat yourself
2 things
create elements from DOM
create function to call elements
What is the event.target?
the element that was targeted/interacted with
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling
event flow, the event starts at the most specific node then flows to least specific
occur on parent of parent etc
What DOM element property tells you what type of element it is?
.tagName property of the element
What does the element.closest() method take as its argument and what does it return?
It takes a selector and return itself or the closest parent that matches the selector.
How can you remove an element from the DOM?
element.remove ( )
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
by adding it to the parent element
What is the event.target?
The element that triggered event
What is the affect of setting an element to display: none?
The element is not displayed and it is removed from the document flow.
What does the element.matches( ) method take as an argument and what does it return?
A string representing the selector and return a boolean value.
How can you retrieve the value of an element’s attribute?
element. getAttribute (‘string’)
At what steps of the solution would it be helpful to log things to the console?
every step
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
use multiple eventlistener and functions
If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
with more IF statements
and functions
What is JSON?
JavaScript Object Notation
strings written in object notation
text based data format to making storing and transferring data easier
data interchange format
What are serialization and deserialization?
serialization is object to string
deserialization is string to object
Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.
Deserialization is the reverse process: turning a stream of bytes into an object in memory.
Why are serialization and deserialization useful?
to make data transferring and storing more efficient
How do you serialize a data structure into a JSON string using JavaScript?
Using JSON.Stringify( )
How do you deserialize a JSON string into a data structure using JavaScript?
JSON. parse ( )
How to you store data in localStorage?
localStorage. setItem ( )
method of the storage interface
key and value
How to you retrieve data from localStorage?
localStorage. getItem ( )
method of the storage interface
needs the key
What data type can localStorage save in the browser?
ONLY string values
When does the ‘beforeunload’ event fire on the window object?
when the window, the document and its resources are about to be unloaded.
What is a method?
A method is a function which is a property of an object.
How can you tell the difference between a method definition and a method call?
the ( ) after the method
function keyword
the arguments
function code block
Describe method definition syntax (structure).
- Method name:
- Function keyword;
- Parameters (optional);
- Opening curly brace;
- Code;
- Closing curly brace.
Describe method call syntax (structure).Describe method call syntax (structure).
- Object.
- Method name;
- Arguments inside parentheses (optional).
How is a method different from any other function?
It is a function stored inside an object as a property.
What is the defining characteristic of Object-Oriented Programming?
Objects can contain both data (as properties) and behavior (as methods).
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
Using something complex, in a simple way.
generalizing
knowing what something does without how it happens
What does API stand for?
Application Programming Interface.
What is the purpose of an API?
a set of functions that allows applications to access data and interact with external software components, operating systems, or microservices.
software abtraction
What is this in JavaScript?
implicit parameter of all JavaScript functions.
the variable whose value is the object that is executing the function
What does it mean to say that this is an “implicit parameter”?
the value of this is determined at call time.
no parameters
When is the value of this determined in a function; call time or definition time?
call time
What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function ( ) { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } };
nothing
Given the above character object, what is the result of the following code snippet? Why?
character.greet( );
It’s-a-me, Mario!
Given the above character object, what is the result of the following code snippet? Why?
It’s-a-me, undefined!
How can you tell what the value of this will be for a particular function or method definition?
you cannot tell
How can you tell what the value of this is for a particular function or method call?
The value of this will be in relation to who made the call.
The value of “this” will be the object that is calling it.
What kind of inheritance does the JavaScript programming language use?
Prototype-based programming is a style of object-oriented programming in which classes are not explicitly defined, but rather derived by adding properties and methods to an instance of another class or, less frequently, adding them to an empty object.
In simple words: this type of style allows the creation of an object without first defining its class.
prototypal
What is a prototype in JavaScript?
A prototype is a model that displays the appearance and behavior of an application or product early in the development lifecycle.
object that other objects can build on
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?
the methods are defined on a prototype object
and are inherited
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
in the prototype
What does the new operator do?
The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
The new keyword is used in javascript to create a object from a constructor function. The new keyword has to be placed before the constructor function call and will do the following things:
Creates a new object
Sets the prototype of this object to the constructor function’s prototype property
Binds the this keyword to the newly created object and executes the constructor function
Returns the newly created object
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
What does the instanceof operator do?
The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value. check the type of an object at the run time.
What is a “callback” function?
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
A callback function is a function which is:
accessible by another function, and
is invoked after the first function if that first function completes
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
setTimeout( ) function
How can you set up a function to be called repeatedly without using a loop?
setInterval( ) function
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
zero
What do setTimeout() and setInterval() return?
setTimeout allows us to run a function once after the interval of time.
This works in a very similar way to setTimeout(), except that the function you pass as the first parameter is executed repeatedly at no less than the number of milliseconds given by the second parameter apart
non zero value
What is a client?
software making use of
party requesting service
What is a server?
provider of the service or resource
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
The browser looks up the IP address for the domain name via DNS. The browser sends a HTTP request to the server.
What three things are on the start-line of an HTTP request message?
HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 2793
The protocol version, usually HTTP/1.1.
A status code, indicating success or failure of the request. Common status codes are 200, 404, or 302
A status text. A brief, purely informational, textual description of the status code to help a human understand the HTTP message.
What three things are on the start-line of an HTTP response message?
GET / HTTP/1.1
Accept: /
Accept-Encoding: gzip, deflate
method
request target
HTTP version
What are HTTP headers?
string followed by a colon (‘:’) and a value whose structure depends upon the header. The whole header, including the value, consist of one single line, which can be quite long.
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
Is a body required for a valid HTTP request or response message?
no
What is AJAX?
Asynchronous JavaScript And XML.
Make requests to the server without reloading the page
Receive and work with data from the server
is a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML.
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest object
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
shared prototype object
What is a code block? What are some examples of a code block?
the code that is in between the curly braces of a function
conditions
loops
return
What does block scope mean?
whatever is in between the code block
what is defined inside the specific block
variable lives and dies within { }
What is the scope of a variable declared with const or let?
block scoped
What is the difference between let and const?
Like the let keyword, the const keyword declares blocked-scope variables. However, the block-scoped variables declared by the const keyword can’t be reassigned.
let is mutable
const is immutable
Why is it possible to .push() a new value into a const variable that points to an Array?
let is mutable
const is not mutable
its not reassignment
value can be changed but not reassigned
How should you decide on which type of declaration to use?
depending if you want something to be constant or not
What is the syntax for writing a template literal?
` text content `
the backticksstring text ${expression} string text
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions.
What is destructuring, conceptually?
assigning properties of an object to individual variables.
the process of unpacking a small part of something from the main part.
What is the syntax for Object destructuring?
let/const/var
{
property Key Name: variable1, property2: variable2
} = object; (destructing)
What is the syntax for Array destructuring?
keyword
[ element names
]
= deconstructed variable
How can you tell the difference between destructuring and creating Object/Array literals?
the object/array would have been assigned already and on the left hand side of the =
What is the syntax for defining an arrow function?
- Variable keyword
- Variable name
- Parameters(optional with 1 parameter)
- Arrow =>
- Bracket (Only required if statement)
single expression OR code block
When an arrow function’s body is left without curly braces, what changes in its functionality?
- The function can only have one line of code
- The code block must be an expression (code that resolves to value)
How is the value of this determined within an arrow function?
- The value of this is determined by it’s parent code block (outward with arrow functions)
lexical scope
its determined when the function is defined outside of the code block
What is a CLI?
command line interface
processes commands to a computer program in the form of lines of text.
that accepts text input to execute operating system functions.
What is a GUI?
graphical user interface
a computer program that enables a person to interact with a computer through the use of symbols, visual metaphors, and pointing devices
a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, instead of text-based user interfaces, typed command labels or text navigation.
man
an interface to the system reference manuals
cat
concatenate files and print on the standard output
ls
list directory contents
pwd
print name of current/working directory
echo
display a line of text
touch
change file timestamps or create a new file
mkdir
make directories
mv
move (rename) files
rm
remove files or directories
cp
copy files and directories
What are the three virtues of a great programmer?
laziness, impatience, hubris
What is Node.js?
an asynchronous event-driven JavaScript runtime
a program executes JavaScript code outside a web browser to make the application faster
usually used in the backend
What can Node.js be used for?
build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform. make things faster like netflix or social media
server side and command line programs
What is a REPL?
A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the use
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
node.js, python, ruby, PHP, Java, .Net, C#, perl
What is a computer process?
a set of instructions currently being processed by the computer processor.
A process is a program that is running on your computer. This can be anything from a small background task
instance of a computer program being executed by one or more threads
instance of a running program
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
over 500
and 2400 theads
Why should a full stack Web developer know that computer processes exist?
Full stack Web development is based on making multiple processes work together to form one application, so having at least a cursory awareness of computer processes is necessary. This will be extremely important when learning about applications made of multiple components, such as clients, servers, and databases.
web dev is based on making multiple processes work together to form one application
What is the process object in a Node.js program?
a global object that can be accessed inside any module without requiring it
How do you access the process object in a Node.js program?
since its global it can be accessed inside any module without requiring it
What is the data type of process.argv in Node.js?
array of strings
What is a JavaScript module?
a single .js file
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, __dirname LOCAL
Give two examples of truly global variables in a Node.js program.
process, console and global
What is the purpose of module.exports in a Node.js module?
Module exports are the instruction that tells Node. js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code
How do you import functionality into a Node.js module from another Node.js module?
use the require function keyword at the top of the file then relative url
What is the JavaScript Event Loop?
the event loop is responsible for executing the code, collecting and processing events, and executing queued sub-tasks
one task at a time to an extent
look at the task queue and pushes it to the stack
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking assignment takes affect immediately it is processed. A nonblocking assignment takes place at the end of processing the current “time delta”
blocking on the stack, nothing else can happen until it gets popped off
non blocking refers to the task not having asynchronous, off the stack
What is a directory?
a file system that contains references to other files
type of file that lists other files
What is a relative file path?
a short hand version of the file url with no root
file path from the current location
What is an absolute file path?
The url with all the information including the root of the file full URL that goes in href
starts with /
What module does Node.js include for manipulating the file system?
‘fs” module or file module
What method is available in the Node.js fs module for writing data to a file?
writeFile method
Are file operations using the fs module synchronous or asynchronous?
asynchronous writefile and readfile
synchronous writefilesync and readfilesync
What is a client?
software making use of party requesting service
program/computer that requests access from another program/computer
What is a server?
provider of the service or resource
program/computer that provides functionality to another program/computer
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
The browser looks up the IP address for the domain name via DNS. The browser sends a HTTP request to the server.
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
The browser looks up the IP address for the domain name via DNS. The browser sends a HTTP request to the server.
What is on the first line of an HTTP request message?
method, target, HTTP version
What is on the first line of an HTTP response message?
protocol version, status code, status text
What are HTTP headers?
let the client and the server pass additional information with an HTTP request or response
meta data for the response or request
Is a body required for a valid HTTP message?
no, they are optional
What is NPM?
large Software Registry for users to share and borrow packages
the registry is a large public database of JavaScript software and the meta-information surrounding it.
the website
the Command Line Interface (CLI)
the registry
node package manager
What is a package?
A package is a file or directory that is described by a package.json file
one or more files with a package.json
packages have a package.json
How can you create a package.json with npm?
go to the root of your directory
npm init –yes
What is a dependency and how to you add one to a package?
Packages required by your application in production.
npm install
What happens when you add a dependency to a package with npm?
npm will download dependencies and devDependencies that are listed in package. json that meet the semantic version requirements listed for each.
package was downloaded by the registry in the directory updates the package dependencies in the package.json
How do you add express to your package dependencies?
create a package.json then install it from the npm registry
npm install express
What Express application method starts the server and binds it to a network PORT?
listen method
app.listen()
How do you mount a middleware with an Express application?
use method of app object
Middleware functions are functions that have access to the request object (req), the response object (res)
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
the request object ( req ), the response object ( res )
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
Content-Type: application/json; charset=utf-8
What does the express.json() middleware do and when would you need it?
to parse the incoming requests with JSON payloads and is based upon the bodyparser
What are the three states a Promise can be in?
pending: initial state, neither fulfilled nor rejected,
fulfilled: meaning that the operation was completed successfully,
rejected: meaning that the operation failed.
How do you handle the fulfillment of a Promise?
then method
How do you handle the rejection of a Promise?
catch method
What is Array.prototype.filter useful for?
creating a new array of elements that pass a filter test implemented by the provided function.
filter((element) => { /* … */ } )
What is Array.prototype.map useful for?
Creating a new array containing the transformed elements of another. The map() method creates a new array populated with the results of calling a provided function on every element in the calling array. map((element) => { /* ... */ })
What is Array.prototype.reduce useful for?
Combining the elements of an array into a single value.
similar to aggregate
reduce((previousValue, currentValue) => { /* … */ } )
name parameters the value you want
name second parameter element of array
What is “syntactic sugar”?
syntactic changes in code to make the code more clear and concise
What is the typeof an ES6 class?
constructor function
Describe ES6 class syntax.
class Person { constructor(name) { this.name = name; } getName() { return this.name; } } class keyword constructor method to initialize the properties of an instance.
What is “refactoring”?
restructuring code without changing its behavior
What is React?
A JavaScript library for building user interfaces for building user interfaces based on UI components.
What is a React element?
an element in the dom
React elements are plain objects, desribes what you want the DOM to look like
A React element is an object representation of a DOM node or component instance building blocks
an object describing a component instance or DOM node and its desired properties
desribes what you want the DOM to look like
How do you mount a React element to the DOM?
with the render method of the reactdom object
ReactDOM.render(element, container[, callback])
How do you mount a React element to the DOM?
ReactDOM.render( )
method
What is Babel?
a JavaScript compiler
mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments
What is a Plug-in?
a software component(branch of software) that adds a specific feature to an existing computer program
What is a Webpack loader?
are transformations that are applied to the source code of a module They allow you to pre-process files as you import or “load” them A Webpack loader is a node module that applies transformations to the source code to of a module and outputs JavaScript
How can you make Babel and Webpack work together?
Install all dev dependencies
- webpack
- webpack-cli
- babel-loader
- @babel/core
- @babel/plugin-transformation-react-jsx
Configure webpack.config.js file to
- use babel loader as the loader
- use plugin transform react jsx
by adding babel-loader to the list of modules in webpack.config
What does fetch() return?
A promise that resolves to a response object.
a promise for a response
What is the default request method used by fetch()?
GET
How do you specify the request method (GET, POST, etc.) when calling fetch?
The 2nd argument is going to be an object literal with the property Method then the request method.
What must the return value of myFunction be if the following expression is possible?
myFunction()();
return of myFunction
returns the function
What does this code do? const wrap = value => () => value;
assigns the return of the second function to a variable
wrap is storing a function definition and that definiton is also another function definition
returns the value
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
when it is defined
What allows JavaScript functions to “remember” values from their surroundings?
closures