Objects Flashcards

1
Q

var person = {
name : “steve”,
age : 24,
}

two ways to access

A

person[‘name’]

person.name

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

var person = {
name : “steve”,
age : 24,
}

set name to “bob”

A
person.name = "bob"
person["name"] = "bob"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

var person = {
name : “steve”,
age : 24,
}

add country Brazil

A
person.country = "Brazil"
person["country'] = "Brazil"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

let user = { name: “John”, age: 30 };

alert( “age” ________); // true, user.age exists

A

in user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
let user = {
  name: "John",
  age: 30,
  isAdmin: true
};

for (let key in user) {

alert( key ); //

}

A

name, age, isAdmin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
let user = {
  name: "John",
  age: 30,
  isAdmin: true
};

for (let key in user) {

alert( user[key] ); //
}

A

John, 30, true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
let codes = {
  "49": "Germany",
  "41": "Switzerland",
  "44": "Great Britain",
  // ..,
  "1": "USA"
};

for (let code in codes) {
alert(code); //
}

A

1, 41, 44, 49

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
let codes = {
  "+49": "Germany",
  "+41": "Switzerland",
  "+44": "Great Britain",
  // ..,
  "+1": "USA"
};

for (let code in codes) {
alert( code ); //
}

A

49, 41, 44, 1

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

in objects ____________ properties are sorted, others appear in creation order.

A

integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
let a = {};
let b = {};

alert( a == b ); //

A

false

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

An object declared as const can or cannot be changed.

A

can

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

let user = { name: “John”, age: 30 };

alert( “blabla” in user ); //

A

false, user.blabla doesn’t exist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
let a = {};
let b = a; 

alert( a == b );

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
let a = {};
let b = a; 

alert( a === b ); //

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
let a = {};
let b = {};
alert( a == b ); //
A

false

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

We also can use ____________ to replace the loop for simple cloning:

A

Object.assign

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
let user = {
  name: "John",
  age: 30
};

Clone using Object.assign

A

let clone = object.assign({}, user);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
let user = {
  name: "John",
  sizes: {
    height: 182,
    width: 50
  }
};

alert( user.sizes.height ); //

A

182

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
let user = {
  name: "John",
  sizes: {
    height: 182,
    width: 50
  }
};

alert( _________ ); //50

A

user.sizes.width

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

The object constructor, which uses the______ keyword

A

new

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

ADD NEW METHOD NAMED “COLOR”

let user = {
  name: "John",
  age: 30
};
A
user.color = function() {
 //code
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
// Initialize an object
const employees = {
    boss: 'Michael',
    secretary: 'Pam',
    sales: 'Jim',
    accountant: 'Oscar'
};
// Get the keys of the object
const keys = \_\_\_\_\_\_\_\_(employees);

console.log(keys);

A

object.keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
let user = {
name: "John", 
age: 30, 
isAdmin: true 
}; 

for (let key in user) {
alert(________);
} name, age, isAdmin

A

key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
let user = {
name: "John", 
age: 30, 
isAdmin: true 
}; 

for (let key in user) {
alert(________);
} john, 30, true

A

user[key]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
const job = {
    position: 'cashier',
    type: 'hourly',
    isAvailable: true,
    };
// const barista = 
//create a new JOB object
A

Object.create(job);

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

The ___________ method creates a new object, using an existing object as the prototype of the newly created object.

A

Object.create()

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

The ___________ method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.

A

Object.assign()

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

a _______ is something you can do with an object

A

method

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

The _______ determines if an object is frozen.

A

Object.isFrozen()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
const object1 = {
  property1: 42
};
console.log(Object.isFrozen(object1));
// expected output:
A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q
const object1 = {
  property1: 42
};
console.log(Object.isFrozen(object1));
// expected output: false

Object.freeze(object1);

console.log(Object.isFrozen(object1));
// expected output:
A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
const obj = {
  prop: 42
};

Object.freeze(obj);

obj.prop = 33;
//
A

Throws an error in strict mode

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

The __________ method freezes an object. A frozen object can no longer be changed; freezing an object prevents new properties from being added to it, existing properties from being removed, prevents changing the enumerability, configurability, or writability of existing properties, and prevents the values of existing properties from being changed.

A

Object.freeze()

34
Q

The __________method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. Values of present properties can still be changed as long as they are writable.

A

Object.seal()

35
Q
const object1 = {
  property1: 42
};

Object.seal(object1);
object1.property1 = 33;
console.log(object1.property1);
// expected output: ————->

delete object1.property1; // ------>
console.log(object1.property1);
// expected output: --------->
A

33

33

36
Q

The__________ method determines if an object is sealed.

A

Object.isSealed()

37
Q
const object1 = {
  property1: 42
};
console.log(Object.isSealed(object1));
// expected output:

Object.seal(object1);

console.log(Object.isSealed(object1));
// expected output:
A

false

true

38
Q

The ___________ method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.

A

Object.assign()

39
Q
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };

const returnedTarget = Object.assign(target, source);

console.log(target);
// expected output: 
console.log(returnedTarget);
// expected output:
A

Object { a: 1, b: 4, c: 5 }

Object { a: 1, b: 4, c: 5 }

40
Q

The_________ method returns an array of a given object’s own property names, in the same order as we get with a normal loop.

A

Object.keys()

41
Q
const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};
console.log(Object.keys(object1));
// expected output:
A

Array [“a”, “b”, “c”]

42
Q
const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};
console.log(\_\_\_\_\_\_\_\_\_\_(object1));
// expected output: Array ["a", "b", "c"]
A
const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
43
Q
var arr = ['a', 'b', 'c'];
console.log(Object.keys(arr)); // console:
A

[‘0’, ‘1’, ‘2’]

44
Q
var obj = { 0: 'a', 1: 'b', 2: 'c' };
console.log(Object.keys(obj)); // console:
A

[‘0’, ‘1’, ‘2’]

45
Q
var anObj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.keys(anObj)); // console:
A

[‘2’, ‘7’, ‘100’]

46
Q
var anObj = { "+100": 'a', "+2": 'b', "+7": 'c' };
console.log(Object.keys(anObj)); // console:
A

[‘100’, ‘2’, ‘7’]

47
Q

The________ method returns an array of a given object’s own enumerable property values, in the same order as that provided by a for…in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).

A

Object.values()

48
Q
const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};
console.log(Object.values(object1));
// expected output:
A

Array [“somestring”, 42, false]

49
Q
const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};
console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_);
// expected output: Array ["somestring", 42, false]
A

(Object.values(object1)

50
Q

The _____ determines if an object is frozen.

A

The Object.isFrozen() determines if an object is frozen.

51
Q
const object1 = {
  property1: 42
};
console.log(Object.isFrozen(object1));
// expected output: ------------>

Object.freeze(object1);

console.log(Object.isFrozen(object1));
// expected output: ---------------->
A

false

true

52
Q

The _______method returns a string representing the source code of the function.

A

toString()

53
Q
function sum(a, b) {
  return a + b;
}
console.log(sum.toString());
// expected output: ------->
A

“function sum(a, b) {

return a + b};

54
Q
function sum(a, b) {
  return a + b;
}
console.log(\_\_\_\_\_\_\_\_\_\_\_);
// expected output: "function sum(a, b) {
//                     return a + b;
//                   }"
A

sum.toString());

55
Q

The _________ method determines if an object is extensible (whether it can have new properties added to it).

A

Object.isExtensible()

56
Q

const object1 = {};

console.log(Object.isExtensible(object1));
// expected output:
A

true

57
Q
// New objects are extensible.
var empty = {};

TRUE/FALSE

A

TRUE

58
Q
var sealed = Object.seal({});
Object.isExtensible(sealed); // ===

TRUE/FALSE

A

false

59
Q

TRUE/FALSE

var frozen = Object.freeze({});
Object.isExtensible(frozen); // ===
A

false

60
Q
function Dog(name) {
  this.name = name;
}

var dog1 = new Dog(‘Gabby’);

Dog.prototype.toString = function dogToString() {
return ‘’ + this.name;
}

console.log(dog1.toString());
// expected output:
A

“Gabby”

61
Q

The __________method checks if an object exists in another object’s prototype chain.

A

isPrototypeOf()

62
Q
function object1() {}
function object2() {}
const object3 = new object1();
console.log(object2.prototype.isPrototypeOf(object3));
A

false

63
Q
function object1() {}
function object2() {}

object1.prototype = Object.create(object2.prototype);

const object3 = new object1();

console.log(object1.prototype.isPrototypeOf(object3));
// expected output: --------->
console.log(object2.prototype.isPrototypeOf(object3));
// expected output: ---------->
A

true

true

64
Q

The ____________ method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it).

A

hasOwnProperty()

65
Q
const object1 = new Object();
object1.property1 = 42;
console.log(object1.hasOwnProperty('property1'));
// expected output:
A

true

66
Q
const object1 = new Object();
object1.property1 = 42;
console.log(object1.hasOwnProperty('toString'));
// expected output:
A

false

67
Q
const object1 = new Object();
object1.property1 = 42;
console.log(object1.hasOwnProperty('hasOwnProperty'));
// expected output:
A

false

68
Q

hasOwnProperty returns true even if the value of the property is_____ or________.

A

null

undefined

69
Q

o = new Object();

o. propOne = null;
o. hasOwnProperty(‘propOne’); // returns
o. propTwo = undefined;
o. hasOwnProperty(‘propTwo’); // returns

A

true

true

70
Q

o = new Object();

o. hasOwnProperty(‘prop’); // returns
o. prop = ‘exists’;
o. hasOwnProperty(‘prop’); // returns

A

false

true

71
Q

o = new Object();

o. prop = ‘exists’;
o. hasOwnProperty(‘prop’); // returns

A

true

72
Q

o = new Object();

o. prop = ‘exists’;
o. hasOwnProperty(‘toString’); // returns

A

false

73
Q
const prototype1 = {};
const object1 = Object.create(prototype1);
console.log(Object.getPrototypeOf(object1) === prototype1);
// expected output:
A

true

74
Q
var proto = {};
var obj = Object.create(proto);
Object.getPrototypeOf(obj) === proto; //
A

true

75
Q
function sayHello2(name) {
  var text = 'Hello ' + name; // Local variable
  var say = function() { console.log(text); }
  return say;
}
var say2 = sayHello2('Bob');
say2(); // logs
A

“Hello Bob”

76
Q
function say667() {
  // Local variable that ends up within closure
  var num = 42;
  var say = function() { console.log(num); }
  num++;
  return say;
}
var sayNumber = say667();
sayNumber(); //
A

logs 43

77
Q

Without using new keyword how we could use these functions. So JavaScript has 3 different ways to do that:

A
  1. call the function as a regular function
  2. attach them to an object, as its properties
  3. Use this, which is using call or apply to invoke the function
78
Q

The ______method calls a function with a given this value and arguments provided as an array (or an array-like object).

A

apply()

79
Q

The_________ method calls a function with a given this value and arguments provided individually.

A

call()

80
Q
const object1 = new Object();
object1.property1 = 42; 

console.log(Object.prototype.hasOwnProperty(‘hasOwnProperty’));

A

TRUE