Quiz 1 Flashcards
temporal dead zone
When you try to access a variable before it has been declared/the “area”/time between the start of a scope and when a variable is actually declared
What is an object?
An object is a container of properties
What are properties and what can they contain?
Properties belong to objects and have names/“key” and values. They can take any values including other objects and functions
What is a prototype?
Inherited properties from another object is called a prototype
What is the highest level of a prototype
Object.prototype
What is the prototype of “hello” and the prototype of that prototype?
- String.prototype 2. Object.prototype
A property is found by first looking if the object itself contains the property then that object’s prototype and so on until……
it reached an object will null as the prototype such as Object.prototype
Give an example of two methods that Object.prototype contains
toString and hasOwnProperty
Give an example of two object that Object.prototype contains
String.prototype and Array.prototype
Object.create
Object.create(otherObject)
Used to create objects with a specified prototype
What does using this.object do when using a constructor?
Creates a property name and value for every new object instantiated with the constructor
i.e.
this.names = [‘jane’, ‘mary’]
c = new Name
d = new Name
c.names will = jane
d.names will = mary
hasOwnProperty vs this.object
hasOwnProperty can set properties by inheriting, and this.object creates new/original properties
Asynchronous programming allows…?
Allows multiple things to run at the same time. Allows part of code to start now, and finish later
What is a callback function?
A function that’s passed into another function, that when called will be called with the result
What is a higher order function?
A function that takes a function(s) as a parameter, or that returns a function
Give a few examples of builtin higher order functions
foreach, map, reduce, filter
Why do we use/make higher order functions?
When we would have to do a bunch of extra things that deal with unimportant details. If we want to repeat the implementation/basic idea of a function on different parameters
How are classes defined
class Name {
constructor(){}
methodOne(){}
}
What is Object.prototype’s prototype
null
Objects can be given prototypes in 3 ways:
Object.create, constructor functions, (ES6) classes
Define constructor and instance. Write an example block of code
Constructor is a function with the “new” keyword, and creates an object/instances with the defined prototypes.
Instance is an object created by using the “new” keyword and constructors. You can also say instances are the children of constructors.
function ConstructorName(attr){
this.attr = attr
}
const newInstance = new ConstructorName(‘unique_attr’)