Week 4 Flashcards

1
Q

What is a method?

A

A method is a function that is the property of an object

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

How can you tell the difference between a method definition and a method call?

A

Method definition has the function keyword and a code block vs the method call has dot notation and the object we are calling it on

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

Describe method definition syntax (structure)

A

property name: function (parameters) {
codeblock
}

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

Describe method call syntax (structure).

A

object.methodName(parameters, if any)

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

How is a method different from any other function?

A

a method requires the object you are calling it on

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

What is the defining characteristic of object-oriented programing?

A

it contains both data and behavior
data in the form of attributes/properties
code in the form of procedures/methods

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

What are the 4 principles of Object-Oriented Programming?

A

Abstraction, encapsulation, inheritance, and polymorphism

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

What is “abstraction”?

A

Abstraction allows us to work with complex things in simple ways
ex: light switch, DOM

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

What is the purpose of an API?

A

It’s a way for computer programs to communicate with each other

API is consisted of abstractions created to allow you to interact with a complex system

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

What is this in JavaScript?

A

It’s an implicit parameter available in any function

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

What does it mean to say that this is an “implicit parameter”?

A

It’s available in a function’s code block even though it was never included in the list of parameters or declared as a variable

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

When is the value of this determined in a function? Call time or definition time?

A

call time

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

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);
}
};

A

this is nothing because the function is not being called

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

var character = {
firstName: ‘Mario’,
greet: function () {
var message = ‘It's-a-me, ‘ + this.firstName + ‘!’;
console.log(message);
}
};
Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

the answer is ‘It’s-a-me, Mario” because the value of this is the object character. character.firstName = Mario

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

var character = {
firstName: ‘Mario’,
greet: function () {
var message = ‘It's-a-me, ‘ + this.firstName + ‘!’;
console.log(message);
}
};
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();

A

The result is ‘It’s-a-me, undefined” because when the function is being called, there is no object directly to the left of it. By default, the value of object is the window object. Window object does not have a firstName property so it is undefined

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

How can you tell what the value of this will be for a particular function/method definition

A

You can’t because the function/method is not being called

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

How can you tell what the value of this is for a particular function or method call?

A

Look to the left of the function call. The value of this will be the object to the left. If there is no object, the default value will be the window object

18
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based / Prototypal inheritance

19
Q

What is a prototype in JavaScript?

A

An object that contains properties and methods that can be used by other objects

20
Q

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?

A

Because of prototype objects

21
Q

If an object does not have its own property or method by a given key, where does JavaScript look for it?

A

inside the object’s prototype object

22
Q

What does the new operator do?

A
  1. Creates a blank, plain javascript object
  2. Assigns the value of the prototype property of the function as the value of the __ proto__ property of the new object
  3. constructor function is called with the given arguments and the value of this becomes the object that was created
  4. The object becomes the return value
23
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

prototype property

24
Q

What does the instanceof operator do?

A

returns boolean
Tests the presence of constructor.prototype in an object’s prototype chain

long story short:
basically checks to see if object was created with a constructor function

25
Q

What is a callback function?

A

a function passed into another function as an argument

26
Q

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?

A

setTimeout(function, delay)

27
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval(function, delay)

28
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0 –> no delay –> code executes immediately

29
Q

What do setTimeout() and setInterval() return?

A

the intervalID which is a numeric value
the intervalID # will be the number of the timer on the page, ex: the first timer will have an intervalID of 1

30
Q

What is a client?

A

Something that requests content or service from a server
Piece of software or hardware who’s purpose is to request resources from a server

31
Q

What is a server?

A

Something that runs one or more programs, which share their resources with clients
Provides responses/resources to client requests

32
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET method

33
Q

What are three things on the start-line of an HTTP request message?

A
  1. HTTP method that describes the action to be performed
  2. The request target (usually URL or absolute path)
  3. HTTP version - indicates the expected version to use for the response
34
Q

What three things are on the start-line of an HTTP response message?

A
  1. Protocol version, usually HTTP/1.1
  2. Status code - indicating success or failure of request
  3. Status text - brief textual description of status code meaning
35
Q

What are HTTP headers?

A

Provides meta-data about the request

36
Q

Is a body required for a valid HTTP request or response message?

A

No.

37
Q

What is AJAX?

A

technique for loading data into part of your page without having to refresh the entire page

38
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

39
Q

What object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest

40
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

Load event

41
Q

An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

Event target prototype