Ad. Javascript.info part 1 Flashcards

Advanced working with functions - Recursion and stack - Rest parameters and spread operator

1
Q

An object is a ________________.

A

collection of properties and has a single prototype object.

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

The prototype of an object may be ______ or ______

A

either an object or the null value

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

A prototype of an object is referenced by the hidden internal _________ and property

A

[[Prototype]]

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

A finite chain of objects which is used to implement inheritance and shared properties

A

Prototype chain

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

code reuse stylistics is called the

A

class-based inheritance

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

is the actual object that is used in the lookup chain to resolve methods, etc.

A

__proto__ or [[prototype]]

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

is the object that is used to build __proto__ when you create an object with new:

A

prototype

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

If the property is not found after the whole prototype chain lookup, then ________ is returned.

A

undefined value

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

Object.prototype itself also has a __proto__, which is the final link of a chain and is set to______.

A

null

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

a constructor function does another useful thing — it automatically sets a ___________ for newly created objects.

A

prototype object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
function Foo(y) {
  this.y = y;
}
// inherited property "x" using constructor
\_\_\_\_\_\_\_\_\_\_\_\_\_\_= 10;
A

Foo.prototype.x

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

every object has a prototype

TRUE / FALSE

A

TRUE

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

An object specifies its prototype via the internal property_________

A

[[Prototype]]

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

What constitute a prototype chain are the __proto__ pointing up the chain, and the objects pointed to by __proto__, such as going from foo.__proto__, going up to foo.__proto__.__proto__, and so forth, until _______

A

null is reached.

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

By default, JavaScript engine provides the Object() funtion and an anonymous object that can be referenced to via the ________

A

Object.prototype.

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

The Object.prototype object has many built-in properties such as toString(), valueOf(), etc. It also has a property named_______ that points back to the _________

A

constructor

Object() function

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

console.log(Object.prototype.constructor !== Object); //

A

false

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

console.log(Object.prototype.constructor === Object); //

A

true

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

let point = {
x: 10,
y: 20,
};

how many properties?
how many __proto__?

A

2 properties

1 __proto__

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

Every object, when is created, receives it’s ______

A

prototype

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

If the prototype is not set explicitly, objects receive _________as their inheritance object.

A

default prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
// Base object.
let point = {
  x: 10,
  y: 20,
};
// Inherit from `point` object.
let point3D = {
  z: 30,
  \_\_proto\_\_: point,
};

inherited or own

console.log(
  point3D.x, // 10,
  point3D.y, // 20,
  point3D.z  // 30,
);
A

inherited

inherited

own

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

a delegation object used to implement prototype-based inheritance.

A

protoype

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

finite chain of objects used to implement inheritance and shared properties.

A

prototype chain

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

a mechanism used to resolve a property in the inheritance chain. The process happens at runtime, hence is also called dynamic dispatch.

A

delegation

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

delegation

A

a mechanism used to resolve a property in the inheritance chain. The process happens at runtime, hence is also called dynamic dispatch.

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

another name for delegation

A

dynamic dispatch.

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

let empty = {};

console.log(empty.x);

A

// undefined

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

To create a prototype-less dictionary, we have to explicitly set its prototype to ______

A

null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
// Doesn't inherit from anything.
let dict = \_\_\_\_\_\_\_\_\_\_
A

Object.create(null);

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

let dict = Object.create(null);

console.log(dict.toString); //

A

undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
let protoA = {x: 10};
let protoB = {x: 20};

CREATE OBJECTC WRITE USING __PROTO__

console.log(objectC.x); // 10

A

let objectC = {__proto__: protoA};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q
let protoA = {x: 10};
let protoB = {x: 20};

CREATE OBJECTC WRITE USING .CREATE

console.log(objectC.x); // 10

A

let objectC = Object.create(protoA);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q
let protoA = {x: 10};
let protoB = {x: 20};

// Change the delegate to protoB DONT USE __PROTO__

console.log(objectC.x); // 20

A

Object.setPrototypeOf(objectC, protoB);

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

When several objects share the same initial state and behavior, they form a________

A

classification

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

________ is a formal abstract set which specifies initial state and behavior of its objects.

A

a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q
var a = {}; 
Object.getPrototypeOf(a); //
alert(a.\_\_proto\_\_);
A

[object Object]

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

a________ function creates objects, and also automatically sets the prototype for its newly created instances

A

constructor

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

Object is an unordered or ordered collection of key-value pairs.

A

unordered

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q
function A() {
  this.x = 10;
  return [1, 2, 3];
}
var a = new A();
console.log(a.x, a);
A

undefined, [1, 2, 3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q
function A() {}
var a = new A();
console.log(a.constructor); // 
console.log(a.constructor === A); //
A

function A() {}, by delegation

true

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

As opposed to object literals, here, you define an object type without any specific values. Then, you create new object instances and populate each of them with different values.

A

constructor function

43
Q

4 ways to create a object

A

with object literals
using a constructor function
with ECMAScript 6 classes
with the Object.create() method

44
Q

The use of __proto__ is controversial, and has been discouraged.

TRUE / FALSE

A

TRUE

45
Q

Allows the addition of properties to all objects of type Object.

A

Object.prototype

46
Q

Object.prototype has a value of

A

1

47
Q

What are the 4 characteristics of Protypal Inheritance in JavaScript

A
  • Prototype Chain - behavior is delegated up the prototype chain if it is not available on the new object
  • .prototype links the function to an object
  • [[Prototype]] internally links one object to another (not public)
  • __proto__ (dunder proto) “public property” a getter function which returns the prototypal linkage of THIS
48
Q

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

A

__proto__

49
Q

Object.getPrototypeOf(obj) –

A

returns the [[Prototype]] of obj (same as __proto__ getter).

50
Q

returns the [[Prototype]] of obj (same as __proto__ getter).

A

Object.getPrototypeOf(obj) –

51
Q

Object.setPrototypeOf(obj, proto) –

A

sets the [[Prototype]] of obj to proto (same as __proto__ setter).

52
Q

sets the [[Prototype]] of obj to proto (same as __proto__ setter).

A

Object.setPrototypeOf(obj, proto) –

53
Q

In JavaScript, objects have a special HIDDEN property __________ (as named in the specification), that is either null or references another object.

A

[[Prototype]]

54
Q

Object constructors are used to create an _________

A

instance of an object

55
Q

in Javascript every function expression is a _____

A

constructor.

56
Q

WHAT IS MISSING

let x = function ( ) {
this.k = k;
}
A

( k )

57
Q

__proto___ means what?

A

parent or creator

58
Q

Whats a prototype in Javascript?

A

a property that every function you create in javascript has, that points to an object

59
Q

the entity behind almost all objects_______

A

Object.prototype.

60
Q

Object.getPrototypeOf({}) ==Object.prototype);

A

true

61
Q

Object.getPrototypeOf(Object.prototype)

A

null

62
Q

The _____________ is an internal linkage that tight one object to another.

A

double bracket [[Prototype]]

63
Q

A constructor is called with the _____ keyword.

A

new

64
Q

A constructor names must start with a _________

A

capital letter

65
Q
function Foo() {}
var f = new Foo();
Object.getPrototypeOf(f) === Foo.prototype

TRUE / FALSE

A

TRUE

66
Q

This is what type of of object

Function User(firstName, lastName, dateOfBirth) {
      this.firstName = firstName;
      this.lastName = lastName;
      this.dateOfBirth = dateOfBirth;
}

var user001 = new User(“John”, “Smith”, 1985);

A

CONSTRUCTOR FUNCTIONS

67
Q

This is what type of of object

var user001 = {
   firstName: "John",
   lastName: "Smith",
   dateOfBirth: 1985,
   getName: function(){
      return "User's name: " + this.firstName + " " + this.lastName;
   }
};
A

OBJECT LITERALS

68
Q

This is what type of of object

class User {
   constructor(firstName, lastName, dateOfBirth) {
      this.firstName = firstName;
      this.lastName = lastName;
      this.dateOfBirth = dateOfBirth;
      this.getName = function(){
          return "User's name: " + this.firstName + " " + this.lastName;
      }
   }
}

var user001 = new User(“John”, “Smith”, 1985);

A

ECMASCRIPT 6 CLASSES

69
Q

This is what type of of object

var user001 = {
   firstName: "John",
   lastName: "Smith",
   dateOfBirth: 1985,
   getName: function(){
      return "User's name: " + this.firstName + " " + this.lastName;
   }
};

var user002 = Object.create(user001);

user002.firstName = “Jane”;

A

THE OBJECT.CREATE() METHOD

70
Q

Make a blank object using the Object() constructor:

var d =

A

new Object();

71
Q

Make a blank object using Object.create() method set to null

var d =

A

Object.create(null);

72
Q

Make a blank object using the bracket’s syntactig

var d =

A

{}

73
Q

You can find instanceof relationships by comparing a function’s prototype to an object’s ________ chain, and you can break these relationships by changing prototype.

A

__proto__

74
Q

_________is a property of a Function object

A

prototype

75
Q

Two ways to point to a prototype

A

__proto__

Object.getPrototypeOf( )

76
Q
function Point(x, y) {
    this.x = x;
    this.y = y;
}
var myPoint = new Point();

WRITE THE REVERSE:
myPoint instanceof Point;
myPoint instanceof Object

A

myPoint.__proto__ == Point.prototype

myPoint.__proto__.__proto__ == Object.prototype

77
Q
function Point(x, y) {
    this.x = x;
    this.y = y;
}
var myPoint = new Point();

WRITE THE REVERSE:
myPoint.__proto__ == Point.prototype
myPoint.__proto__.__proto__ == Object.prototype

A

myPoint instanceof Point;

myPoint instanceof Object

78
Q
let f = new function ()
let o = new object ()
let a = new array (0

ALL in hertiate from:

A

object.prototype

79
Q

Function objects inherit from ________

A

Function.prototype.

80
Q

Funtion.protype inherits from

A

object.prototype

81
Q

to look up the prototype chain we use _______

A

__proto__

82
Q

with constructor functions we dont need the _____ keyword

A

return

83
Q
function createCircle (radius){
return {
    radius,
    draw () {
        console.log('draw');
    }
};
}

What type of function?

A

factory

84
Q

____________ is the default toString representation of an object in javascript.

A

[object Object]

85
Q

Function objects:

stringify(function (){}) ->

A

[object Function]

86
Q

Array objects:

stringify([]) ->

A

[object Array]

87
Q

RegExp objects

stringify(/x/) ->

A

[object RegExp]

88
Q

Date objects

stringify(new Date) ->

A

[object Date]

89
Q

Object objects!

stringify({}) ->

A

[object Object]

90
Q

4 pillars (concepts of OOP)

A

encapsulation
abstraction
inheritance
polymorphism

91
Q

encapsulation does

A

reduce complexity + increase reusability

92
Q

abstraction

A

reduce complexity + isolate impact of change

that hides the internal implementation details

93
Q

inheritance

A

eliminate redundant code

94
Q

polymorphism

A

refactor switch / case statement

95
Q

What are the 3 Attributes of Object Data Properties?

A
  1. Configurable - tells if you can delete or change
  2. Enumerable - can be returned in a for/in loop
  3. Writable - property can be changed
96
Q

Difference between class and an object?

A

An object is an instance of a class. Objects hold any information , but classes don’t have any information. Definition of properties and functions can be done at class and can be used by the object.

Class can have sub-classes, and an object doesn’t have sub-objects.

97
Q
typeof Object
//
A

‘function’

98
Q
typeof new Object()
//
A

‘object’

99
Q

The__________ method is a special method for creating and initializing an object created within a class.

A

constructor

100
Q
function A() {}
var a = new A(); 
console.log(a.constructor); //
A

ƒ A() {}

101
Q
function A() {}
var a = new A(); 
console.log(A.constructor); //
A

ƒ Function() { [native code] }

102
Q

Object.prototype.a = 5;

var v = {};
console.log(v.a); //
A

5

103
Q

prototype of Object.prototype can be altered

TRUE OR FALSE

A

TRUE