Native Prototypes Flashcards

1
Q
let obj = {};
alert( obj ); //
A

“[object Object]” ?

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

obj = {} is the same as obj = new Object()

TRUE / FALSE

A

TRUE

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

When new Object() is called (or a literal object {…} is created), the [[Prototype]] of it is set to ________

A

object.prototype

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

when obj.toString() is called the method is taken from ____________

A

Object.prototype.

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

let arr = [1, 2, 3];

// it inherits from Array.prototype?
alert( \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ ); // true
A

arr.__proto__ === Array.prototype

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

let arr = [1, 2, 3];

// it inherits from Array.prototype?
alert( arr.\_\_proto\_\_ === Array.prototype ); // ?
A

true

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

let arr = [1, 2, 3];

// then from Object.prototype?
alert( \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ ); // true
A

arr.__proto__.__proto__ === Object.prototype

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

let arr = [1, 2, 3];

// then from Object.prototype?
alert( arr.\_\_proto\_\_.\_\_proto\_\_ === Object.prototype ); //
A

true

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

let arr = [1, 2, 3];

// and null on the top.
alert( \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_); // null
A

arr.__proto__.__proto__.__proto__

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

let arr = [1, 2, 3];

// and null on the top.
alert( arr.\_\_proto\_\_.\_\_proto\_\_ ); //
A

[[object Object]]

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

function f() {}

alert(f.__proto__.__proto__ == Function.prototype); //

A

false

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

function f() {}

alert(f.__proto__. == Function.prototype); //

A

true

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

function f() {}

alert(f.__proto__.__proto__ == Object.prototype); //

A

true, inherit from objects

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

Values _______ and _________ have no object wrappers

A

null

undefined

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

_________ is a term for making a substitute for a method that exists in JavaScript specification, but not yet supported by current JavaScript engine

A

Polyfilling

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

The __proto__ is considered outdated and somewhat deprecated (in browser-only part of the JavaScript standard).

The modern methods are:

A

Object.create(proto[, descriptors]) – creates an empty object with given proto as [[Prototype]] and optional property descriptors.

Object.getPrototypeOf(obj) – returns the [[Prototype]] of obj.

Object.setPrototypeOf(obj, proto) – sets the [[Prototype]] of obj to proto.

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

Object.create(proto[, descriptors])

Does two things

A
  1. creates a new object with assinged prototype

2. gives optional property descriptors. We can provide additional properties to the new object there

18
Q
// fully identical shallow clone of obj
let clone =
A

Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));

19
Q

The __proto__ property is special: it must be either an _____ or _______

A

object

null

20
Q

__________ creates an empty object without a prototype

A

Object.create(null)

21
Q
function Rabbit(name) {
  this.name = name;
}
Rabbit.prototype.sayHi = function() {
  alert( this.name );
}

let rabbit = new Rabbit(“Rabbit”);

rabbit.sayHi(); //

A

Rabbit

22
Q
function Rabbit(name) {
  this.name = name;
}
Rabbit.prototype.sayHi = function() {
  alert( this.name );
}

let rabbit = new Rabbit(“Rabbit”);

Rabbit.prototype.sayHi(); //

A

undefined

23
Q
function Rabbit(name) {
  this.name = name;
}
Rabbit.prototype.sayHi = function() {
  alert( this.name );
}

let rabbit = new Rabbit(“Rabbit”);

Object.getPrototypeOf(rabbit).sayHi(); //

A

undefined

24
Q
function Rabbit(name) {
  this.name = name;
}
Rabbit.prototype.sayHi = function() {
  alert( this.name );
}

let rabbit = new Rabbit(“Rabbit”);

rabbit.__proto__.sayHi(); //

A

undefined

25
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

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

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

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

27
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

The Object.values() 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).

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

Array [“somestring”, 42, false]

29
Q

The _________method returns an array of a given object’s own enumerable string-keyed property [key, value] pairs, 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

The Object.entries() method returns an array of a given object’s own enumerable string-keyed property [key, value] pairs, 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).

30
Q
const object1 = {
  a: 'somestring',
  b: 42
};

for (let [key, value] of Object.entries(object1)) {
console.log(${key}: ${value});
}

A
// "a: somestring"
// "b: 42"
// order is not guaranteed
31
Q

The ___________ method returns an array of all symbol properties found directly upon a given object.

A

The Object.getOwnPropertySymbols() method returns an array of all symbol properties found directly upon a given object.

32
Q
const object1 = {
  a: 1,
  b: 2,
  c: 3
};
console.log(Object.getOwnPropertyNames(object1));
// expected output:
A

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

33
Q

The ______________ method returns an array of all properties (including non-enumerable properties except for those which use Symbol) found directly in a given object.

A

The Object.getOwnPropertyNames() method returns an array of all properties (including non-enumerable properties except for those which use Symbol) found directly in a given object.

34
Q

The static _____________method returns an array of the target object’s own property keys.

A

The static Reflect.ownKeys() method returns an array of the target object’s own property keys.

35
Q

const object1 = {
property1: 42,
property2: 13
};

var array1 = [];

console.log(Reflect.ownKeys(object1));
// expected output:
A

Array [“property1”, “property2”]

36
Q

const object1 = {
property1: 42,
property2: 13
};

var array1 = [];

console.log(Reflect.ownKeys(array1));
// expected output:
A

Array [“length”]

37
Q

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

A

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

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

true

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

false

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

false