m-2-0522 Flashcards
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?
method definition is found inside the declaration of an object
method call is done by using name of the object followed by a period and the name of the method
Describe method definition syntax (structure).
var object = { method: function () { } };
Describe method call syntax (structure).
object.method();
How is a method different from any other function?
A method 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)
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
being able to work with (possibly) complex things in simple ways
What does API stand for?
application programming interface
What is the purpose of an API?
to give programmers a way to interact with a system in a simplified, consistent fashion
What is this in JavaScript?
the value of this is determined by how a function is called
this describes the current context you’re in
What does it mean to say that this is an “implicit parameter”?
meaning that it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var
When is the value of this determined in a function; call time or definition time?
the value of this is determined when the function is called
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); } };
window object
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? var hello = character.greet; hello();
It’s-a-me, undefined!
How can you tell what the value of this will be for a particular function or method definition?
we can’t
How can you tell what the value of this is for a particular function or method call?
Find where the function is called and look for an object to the left of the dot
What kind of inheritance does the JavaScript programming language use?
prototype-based (or prototypal) inheritance
What is a prototype in JavaScript?
a JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?
prototype-based inheritance
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
prototype object
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.
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.
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.
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()
How can you set up a function to be called repeatedly without using a loop?
setInterval()
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
What do setTimeout() and setInterval() return?
The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(). This value can be passed to clearTimeout() to cancel the timeout.
The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.
What is a client?
a service requestor
What is a server?
provider of a resource or service
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, and HTTP version
What three things are on the start-line of an HTTP response message?
The protocol version, a status code, a status text
What are HTTP headers?
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value. Whitespace before the value is ignored.
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?
AJAX is a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest. Ajax allows you to update parts of the DOM of an HTML page without the need for a full page refresh. Ajax also lets you work asynchronously, meaning your code continues to run while the targeted part of your web page is trying to reload (compared to synchronously, which blocks your code from running until that part of your page is done reloading). With interactive websites and modern web standards, Ajax is gradually being replaced by functions within JavaScript frameworks and the official Fetch API Standard.
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
Which object is built into the browser for making HTTP requests in JavaScript?
To perform Ajax communication JavaScript uses a special object built into the browser—an XMLHttpRequest (XHR) object—to make HTTP requests to the server and receive data in response.
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 have a shared prototype object
What is a code block? What are some examples of a code block?
a group of zero or more statements
What does block scope mean?
The current context of execution. The context in which values and expressions are “visible” or can be referenced.
What is the scope of a variable declared with const or let?
block scope
What is the difference between let and const?
let can be updated but not re-declared.
const cannot be updated or re-declared.
Why is it possible to .push() a new value into a const variable that points to an Array?
in this situation, the const variable is a reference to the array. the reference cannot be changed, but the values in the array can be.
How should you decide on which type of declaration to use?
scope
reassignment
redeclaration
What is the syntax for writing a template literal?
To create a template literal, instead of single quotes ( ‘ ) or double quotes ( “ ) quotes we use the backtick ( ` ) character.
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions
What is destructuring, conceptually?
unpack values from arrays, or properties from objects, into distinct variables
What is the syntax for Object destructuring?
const user = { id: 42, isVerified: true };
const {id, isVerified} = user;
console. log(id); // 42
console. log(isVerified); // true
What is the syntax for Array destructuring?
const foo = [‘one’, ‘two’, ‘three’];
const [red, yellow, green] = foo;
console. log(red); // “one”
console. log(yellow); // “two”
console. log(green); // “three”