JS 2 Flashcards

1
Q

What is a method?

A

a function which is a 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
  • a method definition has function definition and code block

- a method call is like a function call with object name dot and method name followed by parenthesis

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

Describe method definition syntax (structure).

A
  • defined as a property with a value of a function in an object literal {methodName: function () {}}
  • after the object’s creation, a function could be assigned to the method name’s property of the object objectName.methodName = function () {}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe method call syntax (structure).

A

object name, dot, method name, parenthesis

objectName.methodName()

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

need dot or bracket notation to see what object the method in

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 Programming?

A
  • objects can contain both properties and methods

- data and behavior are combined

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

What are 4 principles of OOP?

A

Abstraction
Encapsulation
Inheritance
Polymorphism

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

What is “abstraction”?

A
  • removing temporal details to focus on details of greater importance
  • able to work with complex process in simple ways
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does API stand for?

A

application programming interface

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

What is the purpose of an API?

A
  • allows users to use interface independently of implementation
  • can use something without knowing how it was built
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is ‘this’ in JavaScript?

A

a property of an execution context that is a reference to its enclosing object

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

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

A

‘this’ is available in a function’s code block, even though it was never explicitly declared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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
14
Q

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

A

you don’t know until it is called

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

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

A
  • if it is in a method inside an object, then it refers to that object
  • if it is in a function inside the global scope, then it refers to Window
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypical inheritance, which is reusing objects as prototypes to allow for the inheritance of methods and properties

17
Q

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?

A

those methods are defined on those elements’ __proto__ property

18
Q

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

A

looks for it on the prototype object which it is inheriting properties/methods from

19
Q

What does the new operator do?

A
  1. creates an instance object from a constructor function
  2. sets prototype for that object
  3. passes the object as “this”
  4. object that was created is returned
20
Q

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

A

prototype property

21
Q

What does the instanceof operator do?

A
  • tests to see if the prototype property of a constructor appears in the prototype chain of an object
  • returns a boolean whether it is an instance or not