Week 4 Flashcards

(118 cards)

1
Q

In node.js, how is each module defined?

A

JS defines each module

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

what are local modules?

A

modules that are defined within your project

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

how do you make variables and functions that are defined in a module/file accessible to other modules?

A

you have to export them

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

what is the module.exports property used for?

A

to export items from the module

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

what is the single-responsibility principle?

A

“every module, class or function in a computer program should have responsibility over a single part of that program’s functionality”.

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

what is the most accurate phrase for defining the single responsibility principle

A

a function should do one thing and do it well

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

what does the acronym DRY stand for?

A

don’t repeat yourself

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

what does the acronym WET stand for?

A

write everything twice

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

are the module.exports property names bananable?

A

yes, but it makes sense to keep the property names consistent with the item names

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

what does node initialize the module.exports property to?

A

an empty object

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

what is the exports variable initialized to?

A

the module.exports property value

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

what are the options for exporting multiple items from a module?

A
  1. assigning an object to the module.exports property
  2. set properties on the module.exports object
  3. exports shortcut
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how do you export a single item from a module?

A

assign module.exports to the single item

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

if you export just a single item from a module, can you export more items later?

A

no

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

what does it mean for a module to be dependent on another module?

A

the module requires something from another,
a module’s dependencies are the other modules required for it to run properly

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

What is the other term for a module’s dependencies?

A

a requirement

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

assign an object to the module.exports property with the properties of add and subtract

A

module.exports = {
add,
subtract
};

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

set the properties of add and subtract directly on the module.exports object

A

module.exports.add = add
module.exports.subtract = subtract

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

use the exports shortcut to add the add function as a property onto the exports object

A

exports.add = add

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

what is the format to export a single item from a module; export the multiply function

A

module.exports = multiply

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

what does the built-in require function allow us to do?

A

import items from a module

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

how does the require function work?

A

it takes in a relative path from the module in which require is being called (the module that you wish to export into), to the module you wish to import

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

when importing JS files, what are you able to omit?

A

the .js in the file path

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

how are multiple items exported from a module?

A

as properties of the exported object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
how does the theortical process work behind exporting multiple items?
you can import the object and access the properties of the object to get the desired items
26
what is different about importing an item from a module that has a single export?
you can just use the require function without object destructuring; the return of the require function will be the single item that was exporter
27
can a folder be loaded as a module in Node.js?
yes
28
what must a folder loaded as a module in node.js have?
a file called index.js which will be the only file that Node.js will look for and load
29
what would the format be to load the index.js file in the people folder as a module be?
cost people = require('../people');
30
is scope the same thing as contex?
no
31
what does scope refer to?
the visibility and avaliability of variables
32
what does context refer to?
the value of the this keyword when code is executed
33
what does the value of the this keyword depend on in method-style execution?
where and how a function is invoked
34
what is the format for the method-style invokation?
object.method(args)
35
what does using method-stlye invocation ensure?
the method will be invoked and that the this within the method will be the object that method was called on
36
what do functions in Node that are not defined have as their context?
the global object which is also their this
37
how do you indicate that you want to run Js in strict mode?
out the string "use strict" at the top of the file
38
what is sloppy mode?
the normal JS environment
39
what is the difference between JS in strict mode vs sloppy?
you cannot access the global object in strict mode, so it cannot accidentally be mutated when invoking functions in unintended contexts
40
in strict mode, what will functions that are not explicitly declared return?
undefined
41
what is the context of invoked functions that are not explicitly defined?
the global object
42
what is the simplest use of the bind function?
to make a function that, no matter how it is called, is called with a particular this value
43
what is the syntax used to bind?
let boundFunc = func.bind(context)
44
what does bind return and what does this mean?
an exotic function; a function with its this bound no matter where that function is invoked; this is a copy of the function that it was called on, but still a new function; bind returns the function with its context set
45
how many arguments can bind accept?
as many as neccessary
46
does the bind accept arguments that are passed in when the bound function is invoked?
yes, these areguments will be appended to the arguments passed in when bound
47
can you change the context of a bound function?
no
48
does calling bind on a function invoke that function
no
49
what is the difference in the return and invocation between the bind function and the call and apply functions?
bind returns a function that can be called multiple times call and apply will invoke the bound function immediately and return the value from that function
50
what is the format for assigning the call function?
let callReturn = func.call(context, ...args)
51
what is the format for the apply function
let applyReturn = func.apply(context,[...args])
52
what is the difference between the apply and call functions
apply takes in an array of arguments call spreads their arguments out in comma-seperated values
53
how many arguments can the apply function take in?
2
54
can you pass an array in to the call function without getting an error message? if yes, what will occer to the items in the array
yes, the array is merged into a string with a length of one
55
what is the context of an arrow function?
where it was defined
56
what is the difference between arrow functionsand normal anonymous functions?
they don't have inherent bindings to a this object based on context, their this is lexically bound an arrow function's this refers to whatever code contains it, not calls it which makes them more flexible for use in method callbacks
57
why should you limit your usage of arrow functions for defining a class method
it will create a new arrow function for each class instance and if you have a lot of instances, you will be creating a lot of functions and this will be added to your application's memory
58
when should you define a class method as an arrow function?
if you are binding the class method when using it more times than you are creating new instances of that class or if you don't care about your application memory and you won't be creating too many instances of the class
59
can you change the context of an arrow function using bind, call, or apply?
no
60
what does a syntax error indicate?
code that does not conform to the syntax of the JavaScript language
61
what does a reference error indicate?
an error when a non-existent variable is referenced (either within your current scope or at all)
62
what does a type error indicate?
an error when a variable or parameter is not of a valid type 1. When an operation cannot be performed because the operand is a value of the wrong type. 2. When you are attempting to modify a value that cannot be changed.
63
what does a range error indicate?
an error for when a numeric variable or parameter is outside of its valid range
64
what does a internal error indicate?
an error in the internal JS engione
65
what does a eval error indicate?
an error with the global eval function
66
what does a URI error indicate?
an error that occurs when encodeURI() or decodeURI() are passed invalid parameters.
67
what is the syntax to create a new error object?
new Error([message[, fileName[, lineNumber]]])
68
what is an error constrictor bascally?
a constructor object
69
do you have to use the new keyword to make an error constructor?
no
70
what are the optional input parametiers for the error constructor?
message fileName lineNumber
71
what keyword do you use to throw your own error?
throw
72
if you throw an error, will the code after the error is thrown be run?
no; program execution will stop
73
what should we use if we want to throw an error, but also want the code to continue execution after being thrown
a try ... catch block
74
what goes in the try portion of a try ... catch block? the catch portion?
the statements that will be attempted go in the try block if an error is thrown it will be caught by the catch block allowing the program to continue execution
75
what type of error can not be caught using a try and catch block and why?
any errors that happen at compile time like syntax errors because they happen at compile time and not run time
76
what type of block can you add to the try-catch block
finally
77
what is special about the finally bloack
this code always runs whether or not an error occurs
78
what are the dangers to using try ... catch blocks frequently in your code?
every block makes your code slow down
79
what should you try to do instead of using frequent try-catch blocks?
write defensive code which checks for bad values before errors get thrown in your code
80
what are the levels of the testing pyramid from lowest to highest?
1. unit tests 2. integration tests 3/ end to end tests
81
what is a unit tests purpose?
test the smallest pieces of your application in isolation to make sure that each peice works; should focus on testing one thing
82
what is the purpose of integration tests?
test the interactions between two pieces of your application; make sure that the units written work coherently
83
what is the purpose of end to end tests
test the whole of the application closet automated tests come to testing the actual user experience of you application
84
what is the slowest type of tests to write
e2e
85
what should your test specs cover?
the functions and pieces that will be used by other modules or classes
86
do test specs guarantee bug free code?
no. there could be bugs or errors that the test specs don't catch or look out for
87
what is test driven development
writing tests before the code is written
88
what is the difference between mocha and chai
Mocha is a test framework that specializes in running tests and presenting them in an organized user friendly way. Chai is an assertion library that performs the actual test comparisons.
89
what are mocha hooks
hooks that are used to set up preconditions and clean up after your tests before() after() beforeEach() afterEach()
90
what is the convention or naming mocha test spec tiles?
appending -spec to the name of the file that you are testing
91
what function in mocha is used to test a single spec?
it
92
what function in chai is used to define when a test spec passes or fails
expect
93
which directory will mocha default to loo in for running test spec files
the test directory
94
Which of the function is used to group test specs in Mocha?
describe
95
what are edge cases?
conditions where your code can break by certain unlikely actions by a user. The edge cases define how a problem performs under uncommon circumstances like invalid inputs or small inputs.
96
what does OOP stand for?
object oriented programming
97
what is object oriented programming?
a common design pattern that helps developers break down large, complex problems into simpler pieces. Implementation details of a single feature are bundled into a single API that interacts with other APIs of different features.
98
what does the equal keyword in chai indicate?
strict equality
99
what does the eql keyword in chai indicate?
loose equality
100
what is OOP?
an approach or mindset for breaking down large, complex products into simple solutions. the smaller parts can then be implemented and tested separately to provide higher confidence in the overall solution;
101
what is OOP used for?
to make code more readable and maintainable
102
what is the main concept behind OOP?
you can group data and related actions or behaviors in order to treat them as a single entity within a larger system
103
what is an object in OOP?
an item containing attributes and behaviors
104
what are the characteristics of an object in OOP called?
properties or attributes
105
what are methods of an object in OOP?
the actions of the object
106
what does encapsulation in OOP mean?
putting all of the details behind an object's data (properties) and behaviors (methods)
107
what are some applications of encapsulation in OOP
hiding the complexity of a behavior in an API separating behavior and data of a problem into multiple objects
108
what can private data do in encapsulation
it can only be accessed and used by its own object
109
what can public data do in encapsulation
it is allowed to be accessed and used by other objects
110
what is a class?
the specification or definition of an object with properties and methods; its like a blueprint; the class specifies the framework of the properties and methods a class is just a framework until it is instantiated
111
what is an instance? how do you make one?
a specific object made from a class a constructor makes an instance
112
what is a constructor
a special method that sets up any actions or data values that need to be set up right away
113
what is the format to create a class
class ClassName {}
114
what does the this keyword refer to within a constructor method's body
the newly created object instance
115
why is it important not to return something from within your constructor method?
because the return value will be what ever you have explicitly returned instead of the new object
116
what is an instance method?
methods that are invoked on a given instance of the class stored in a variable
117
what operator do you use to check if an object is an instance of a specific class?
instanceof
118
what is the difference between instance and static methods
static methods are invoked directly on a class not on an instance