Week 4 Flashcards

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
Q

how does the theortical process work behind exporting multiple items?

A

you can import the object and access the properties of the object to get the desired items

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

what is different about importing an item from a module that has a single export?

A

you can just use the require function without object destructuring; the return of the require function will be the single item that was exporter

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

can a folder be loaded as a module in Node.js?

A

yes

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

what must a folder loaded as a module in node.js have?

A

a file called index.js which will be the only file that Node.js will look for and load

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

what would the format be to load the index.js file in the people folder as a module be?

A

cost people = require(‘../people’);

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

is scope the same thing as contex?

A

no

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

what does scope refer to?

A

the visibility and avaliability of variables

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

what does context refer to?

A

the value of the this keyword when code is executed

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

what does the value of the this keyword depend on in method-style execution?

A

where and how a function is invoked

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

what is the format for the method-style invokation?

A

object.method(args)

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

what does using method-stlye invocation ensure?

A

the method will be invoked and that the this within the method will be the object that method was called on

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

what do functions in Node that are not defined have as their context?

A

the global object which is also their this

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

how do you indicate that you want to run Js in strict mode?

A

out the string “use strict” at the top of the file

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

what is sloppy mode?

A

the normal JS environment

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

what is the difference between JS in strict mode vs sloppy?

A

you cannot access the global object in strict mode, so it cannot accidentally be mutated when invoking functions in unintended contexts

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

in strict mode, what will functions that are not explicitly declared return?

A

undefined

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

what is the context of invoked functions that are not explicitly defined?

A

the global object

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

what is the simplest use of the bind function?

A

to make a function that, no matter how it is called, is called with a particular this value

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

what is the syntax used to bind?

A

let boundFunc = func.bind(context)

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

what does bind return and what does this mean?

A

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

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

how many arguments can bind accept?

A

as many as neccessary

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

does the bind accept arguments that are passed in when the bound function is invoked?

A

yes, these areguments will be appended to the arguments passed in when bound

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

can you change the context of a bound function?

A

no

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

does calling bind on a function invoke that function

A

no

49
Q

what is the difference in the return and invocation between the bind function and the call and apply functions?

A

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
Q

what is the format for assigning the call function?

A

let callReturn = func.call(context, …args)

51
Q

what is the format for the apply function

A

let applyReturn = func.apply(context,[…args])

52
Q

what is the difference between the apply and call functions

A

apply takes in an array of arguments
call spreads their arguments out in comma-seperated values

53
Q

how many arguments can the apply function take in?

A

2

54
Q

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

A

yes, the array is merged into a string with a length of one

55
Q

what is the context of an arrow function?

A

where it was defined

56
Q

what is the difference between arrow functionsand normal anonymous functions?

A

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
Q

why should you limit your usage of arrow functions for defining a class method

A

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
Q

when should you define a class method as an arrow function?

A

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
Q

can you change the context of an arrow function using bind, call, or apply?

A

no

60
Q

what does a syntax error indicate?

A

code that does not conform to the syntax of the JavaScript language

61
Q

what does a reference error indicate?

A

an error when a non-existent variable is referenced (either within your current scope or at all)

62
Q

what does a type error indicate?

A

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
Q

what does a range error indicate?

A

an error for when a numeric variable or parameter is outside of its valid range

64
Q

what does a internal error indicate?

A

an error in the internal JS engione

65
Q

what does a eval error indicate?

A

an error with the global eval function

66
Q

what does a URI error indicate?

A

an error that occurs when encodeURI() or decodeURI() are passed invalid parameters.

67
Q

what is the syntax to create a new error object?

A

new Error([message[, fileName[, lineNumber]]])

68
Q

what is an error constrictor bascally?

A

a constructor object

69
Q

do you have to use the new keyword to make an error constructor?

A

no

70
Q

what are the optional input parametiers for the error constructor?

A

message
fileName
lineNumber

71
Q

what keyword do you use to throw your own error?

A

throw

72
Q

if you throw an error, will the code after the error is thrown be run?

A

no; program execution will stop

73
Q

what should we use if we want to throw an error, but also want the code to continue execution after being thrown

A

a try … catch block

74
Q

what goes in the try portion of a try … catch block? the catch portion?

A

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
Q

what type of error can not be caught using a try and catch block and why?

A

any errors that happen at compile time like syntax errors because they happen at compile time and not run time

76
Q

what type of block can you add to the try-catch block

A

finally

77
Q

what is special about the finally bloack

A

this code always runs whether or not an error occurs

78
Q

what are the dangers to using try … catch blocks frequently in your code?

A

every block makes your code slow down

79
Q

what should you try to do instead of using frequent try-catch blocks?

A

write defensive code which checks for bad values before errors get thrown in your code

80
Q

what are the levels of the testing pyramid from lowest to highest?

A
  1. unit tests
  2. integration tests
    3/ end to end tests
81
Q

what is a unit tests purpose?

A

test the smallest pieces of your application in isolation to make sure that each peice works; should focus on testing one thing

82
Q

what is the purpose of integration tests?

A

test the interactions between two pieces of your application; make sure that the units written work coherently

83
Q

what is the purpose of end to end tests

A

test the whole of the application
closet automated tests come to testing the actual user experience of you application

84
Q

what is the slowest type of tests to write

A

e2e

85
Q

what should your test specs cover?

A

the functions and pieces that will be used by other modules or classes

86
Q

do test specs guarantee bug free code?

A

no. there could be bugs or errors that the test specs don’t catch or look out for

87
Q

what is test driven development

A

writing tests before the code is written

88
Q

what is the difference between mocha and chai

A

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
Q

what are mocha hooks

A

hooks that are used to set up preconditions and clean up after your tests
before()
after()
beforeEach()
afterEach()

90
Q

what is the convention or naming mocha test spec tiles?

A

appending -spec to the name of the file that you are testing

91
Q

what function in mocha is used to test a single spec?

A

it

92
Q

what function in chai is used to define when a test spec passes or fails

A

expect

93
Q

which directory will mocha default to loo in for running test spec files

A

the test directory

94
Q

Which of the function is used to group test specs in Mocha?

A

describe

95
Q

what are edge cases?

A

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
Q

what does OOP stand for?

A

object oriented programming

97
Q

what is object oriented programming?

A

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
Q

what does the equal keyword in chai indicate?

A

strict equality

99
Q

what does the eql keyword in chai indicate?

A

loose equality

100
Q

what is OOP?

A

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
Q

what is OOP used for?

A

to make code more readable and maintainable

102
Q

what is the main concept behind OOP?

A

you can group data and related actions or behaviors in order to treat them as a single entity within a larger system

103
Q

what is an object in OOP?

A

an item containing attributes and behaviors

104
Q

what are the characteristics of an object in OOP called?

A

properties or attributes

105
Q

what are methods of an object in OOP?

A

the actions of the object

106
Q

what does encapsulation in OOP mean?

A

putting all of the details behind an object’s data (properties) and behaviors (methods)

107
Q

what are some applications of encapsulation in OOP

A

hiding the complexity of a behavior in an API
separating behavior and data of a problem into multiple objects

108
Q

what can private data do in encapsulation

A

it can only be accessed and used by its own object

109
Q

what can public data do in encapsulation

A

it is allowed to be accessed and used by other objects

110
Q

what is a class?

A

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
Q

what is an instance? how do you make one?

A

a specific object made from a class
a constructor makes an instance

112
Q

what is a constructor

A

a special method that sets up any actions or data values that need to be set up right away

113
Q

what is the format to create a class

A

class ClassName {}

114
Q

what does the this keyword refer to within a constructor method’s body

A

the newly created object instance

115
Q

why is it important not to return something from within your constructor method?

A

because the return value will be what ever you have explicitly returned instead of the new object

116
Q

what is an instance method?

A

methods that are invoked on a given instance of the class stored in a variable

117
Q

what operator do you use to check if an object is an instance of a specific class?

A

instanceof

118
Q

what is the difference between instance and static methods

A

static methods are invoked directly on a class not on an instance