Module 2 Flashcards
What is a method?
a function that is a property of an object
How can you tell the difference between a method definition and a method call?
the . call
Describe method definition syntax (structure).
__name of method__ : function(__parameters__) {
–code–
}
Describe method call syntax (structure).
__name of obj__ . __name of method__(__args__)
How is a method different from any other function?
it is a property of an object
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods); taking related data and functionality and putting them together in an object
What are the four “principles” of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
What is “abstraction”?
being able to work with complex things in a simple way (ex: light switch, auto transmition in a car, the DOM); a simple interphase that does complex things behind the scenes (ie pushing the gas/brake on a car vs thinking about how the engine delivers power to the wheels, etc)
What does API stand for?
application programming interface
What is the purpose of an API?
to connect computers/pieces of software to each other
What is this in JavaScript?
this is an implicit property of an object that refers to the object itself; when unassigned to an object this = Window object
What does it mean to say that this is an “implicit parameter”?
it is not explicitly defined (like a variable is), it ‘comes with’ the creation of the object; it is defined at the time of the method call
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); } };"
character obj
How can you tell what the value of this will be for a particular function or method definition?
you cant; defined at call time
How can you tell what the value of this is for a particular function or method call?
find where the functionis called and look for the obj to the left of the dot
What kind of inheritance does the JavaScript programming language use?
prototype: objects inherit from other objects
What is a prototype in JavaScript?
an object that passes down properties
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?
prototypal inheritance from the global objs
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
its prototype
What does the new operator do?
creates an instance from a constructor function
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
What does the instanceof operator do?
checks the prototype tree of an object to see if something is there
What is a “callback” function?
a function that is used as an argument for another function
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?
setInterval()
How can you set up a function to be called repeatedly without using a loop?
setInterval( __function__ , __time (ms)_ )
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 ms
What do setTimeout() and setInterval() return?
numeric id for that timer
What is a client?
the client is the one that makes a request of a server (a person, cpu, app, etc)
What is a server?
provide data, service or function; receive requests –> send response
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What three things are on the start-line of an HTTP request message?
http method, request target, http version
What three things are on the start-line of an HTTP response message?
protocol version, status code (ex 404), status text (explains in plain language what the code means)
What are HTTP headers?
specifies req or gives more info about body; meta-info about content, but not the content itself; case-sensitive string + colon + value (structure depends on header)
Where would you go if you wanted to learn more about a specific HTTP Header?
https://httpie.io/docs#usage
Is a body required for a valid HTTP request or response message?
no
What is AJAX?
building webpages using XMLHttpRequest; allows you to update DOM w/out refreshing page
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()
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
they prototypally inherit the addEventListener() from the EventTarget class
What is a code block? What are some examples of a code block?
a code block is a passage of code within a set of braces
What does block scope mean?
the code only applies to within a code block
What is the scope of a variable declared with const or let?
block
What is the difference between let and const?
let can be reassigned; const cannot
Why is it possible to .push() a new value into a const variable that points to an Array?
because the address of the object does not change
How should you decide on which type of declaration to use?
determine if you need to reassign the variable or not
What is the syntax for writing a template literal?
a string wrapped in ` `
What is “string interpolation”?
subbing values of vars into strs
What is destructuring, conceptually?
simply assigning a property’s value to a variable
What is the syntax for Object destructuring?
let {__property name1__ , __property name2__} = __object__
What is the syntax for Array destructuring?
let [__var 1__ , __var2__ ] = __array__
How can you tell the difference between destructuring and creating Object/Array literals?
the [ ] vs { }