Objects Flashcards

1
Q

What are objects?

A
  • collection of variables and functions

- they represent the attributes and behaviour of something used in a program

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

What are variable tied to object called?

A

Properties

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

What are function tied to object called?

A

Methods

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

Properties and methods are also called?

A

Properties = attributes

Methods = behaviors

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

What is dot notation used for? (.currentTime)

A

It can be used to add a property or add a method and can also be used to consume

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

What is the literal notation to create an object?

A

E.g

let nameOfTheObject = {}

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

How do you add property to an object?

A

objectName.property = ‘something’

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

How do you add a method to an object?

A
objectName.functionName = function(){
//cool stuff
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you change the value of an object property?

A

Whit this syntax:

myObject.myProperty = newValue

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

How can a constructor be differentiate from a function?

A

The name in the function is capitalized

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

What is a constructor?

A

A constructor is a function that has as a purpose to create objects

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

Create an object ‘mouse’ and give it 3 property and 1 methods

A

let mouse = {}

mouse. brand = ‘logitech’
mouse. color = ‘black’
mouse. wireless = ‘true’

mouse.leftClick = function() {
consol.log(‘LEFT CLICKKKK’)
}

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

What does the key word ‘this’ indicate?

A

‘This’ is used in constructor to replace the name of the object

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

What is the syntax of a constructor?

A

function. NameOfConstructor (brand,model,color){
this. brand = …
this. model = …
this. color = …

this.something = function{
alert(…)
}
}

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

When a function name starts with a capital letter what does that mean?

A

It means it is a constructor

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

What is the syntax to create a new object using a constructor?

A

let nameOfNewObject = new NameOfConstructor (‘different values’, ‘…’, ‘…’, ‘…’)

17
Q

What is a prototype?

A

It is a fall-back source of property and methods.

18
Q

What happens if an object does not have a property or method?

A

If an object does not have a property or value can go up its prototype chain to check for the value until it hits the global object prototype.

19
Q

What are the 4 pillar of object oriented programming (OOP)?

A
  • Encapsulation
  • Inheritance
  • Abstraction
  • Polymorphism
20
Q

What is encapsulation in OOP?

A

Encapsulation refers to the grouping of related variable and function that operates on them into objects

21
Q

What is abstraction in OOP?

A

It refers to the possibility of hiding some of the property and methods in order to make the interface of those objects simpler and it also helps to reduce the impact of change.

22
Q

What is inheritance in OOP?

A

It helps us to eliminate redundant code that similar element have in common by just defining it once and then have other objects inherit those methods

23
Q

What is polymorphism in OOP?

A

with polymorphism we can restructure ugly switch/case statements