Introduction to objects & Object methods Flashcards

1
Q

What is an object?

A

An object is a collection of properties and a property is an association between a name (or key) and a value.

Example:
const person = {
  firstName: 'James'
  lastName: 'Bond'
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between Objects and Arrays ?

A

The difference between objects and arrays is that in objects the order of the values does not matter when retrieving the values.

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

How can properties be gotten from an object?

A

Properties can be gotten from an object using the Dot and the Bracket notation.

Example:-
DOT NOTATION
console.log(person.firstName);

BRACKET NOTATION
console.log(person[‘firstName’]);

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

What is the difference between the Dot & Bracket Notation.

A

In the Dot notation only the real property name can be used and not a computed property name.

Example:-
USING BRACKET NOTATION
const nameKey = “Name”;
console.log(person.[‘first’ + nameKey]); // output : James.
Note: the above can’t be done using Dot Notation.

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

How are new properties added to objects?

A

DOT NOTATION
person.job = ‘Spy’;

BRACKET NOTATION
person[‘car’] = ‘Aston Martin’;

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

What is an Object method?

A

An object method is a function attached to an object.

Example:-

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

What is an Object method?

A

An object method is a function attached to an object.

Example:-
const person = {
  firstName: 'James',
  lastName: 'Bond',
  calcAge: function(currentYear, birthYear){
    return currentYear - birthYear;
}
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly