Ad. Javascript.info part 1 Flashcards

Advanced working with functions - Recursion and stack - Rest parameters and spread operator (103 cards)

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
a mechanism used to resolve a property in the inheritance chain. The process happens at runtime, hence is also called dynamic dispatch.
delegation
26
delegation
a mechanism used to resolve a property in the inheritance chain. The process happens at runtime, hence is also called dynamic dispatch.
27
another name for delegation
dynamic dispatch.
28
let empty = {}; console.log(empty.x);
// undefined
29
To create a prototype-less dictionary, we have to explicitly set its prototype to ______
null
30
``` // Doesn't inherit from anything. let dict = __________ ```
Object.create(null);
31
let dict = Object.create(null); console.log(dict.toString); //
undefined
32
``` let protoA = {x: 10}; let protoB = {x: 20}; ``` CREATE OBJECTC WRITE USING __PROTO__ console.log(objectC.x); // 10
let objectC = {__proto__: protoA};
33
``` let protoA = {x: 10}; let protoB = {x: 20}; ``` CREATE OBJECTC WRITE USING .CREATE console.log(objectC.x); // 10
let objectC = Object.create(protoA);
34
``` let protoA = {x: 10}; let protoB = {x: 20}; ``` // Change the delegate to protoB DONT USE __PROTO__ console.log(objectC.x); // 20
Object.setPrototypeOf(objectC, protoB);
35
When several objects share the same initial state and behavior, they form a________
classification
36
________ is a formal abstract set which specifies initial state and behavior of its objects.
a class
37
``` var a = {}; Object.getPrototypeOf(a); // alert(a.__proto__); ```
[object Object]
38
a________ function creates objects, and also automatically sets the prototype for its newly created instances
constructor
39
Object is an unordered or ordered collection of key-value pairs.
unordered
40
``` function A() { this.x = 10; return [1, 2, 3]; } ``` ``` var a = new A(); console.log(a.x, a); ```
undefined, [1, 2, 3]
41
``` function A() {} var a = new A(); console.log(a.constructor); // console.log(a.constructor === A); // ```
function A() {}, by delegation true
42
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.
constructor function
43
4 ways to create a object
with object literals using a constructor function with ECMAScript 6 classes with the Object.create() method
44
The use of __proto__ is controversial, and has been discouraged. TRUE / FALSE
TRUE
45
Allows the addition of properties to all objects of type Object.
Object.prototype
46
Object.prototype has a value of
1
47
What are the 4 characteristics of Protypal Inheritance in JavaScript
- 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
The __________ is considered outdated and somewhat deprecated (in browser-only part of the JavaScript standard).
__proto__
49
Object.getPrototypeOf(obj) –
returns the [[Prototype]] of obj (same as __proto__ getter).
50
returns the [[Prototype]] of obj (same as __proto__ getter).
Object.getPrototypeOf(obj) –
51
Object.setPrototypeOf(obj, proto) –
sets the [[Prototype]] of obj to proto (same as __proto__ setter).
52
sets the [[Prototype]] of obj to proto (same as __proto__ setter).
Object.setPrototypeOf(obj, proto) –
53
In JavaScript, objects have a special HIDDEN property __________ (as named in the specification), that is either null or references another object.
[[Prototype]]
54
Object constructors are used to create an _________
instance of an object
55
in Javascript every function expression is a _____
constructor.
56
WHAT IS MISSING ``` let x = function ( ) { this.k = k; } ```
( k )
57
__proto___ means what?
parent or creator
58
Whats a prototype in Javascript?
a property that every function you create in javascript has, that points to an object
59
the entity behind almost all objects_______
Object.prototype.
60
Object.getPrototypeOf({}) ==Object.prototype);
true
61
Object.getPrototypeOf(Object.prototype)
null
62
The _____________ is an internal linkage that tight one object to another.
double bracket [[Prototype]]
63
A constructor is called with the _____ keyword.
new
64
A constructor names must start with a _________
capital letter
65
``` function Foo() {} var f = new Foo(); Object.getPrototypeOf(f) === Foo.prototype ``` TRUE / FALSE
TRUE
66
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);
CONSTRUCTOR FUNCTIONS
67
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; } }; ```
OBJECT LITERALS
68
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);
ECMASCRIPT 6 CLASSES
69
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";
THE OBJECT.CREATE() METHOD
70
Make a blank object using the Object() constructor: var d =
new Object();
71
Make a blank object using Object.create() method set to null var d =
Object.create(null);
72
Make a blank object using the bracket's syntactig var d =
{}
73
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.
__proto__
74
_________is a property of a Function object
prototype
75
Two ways to point to a prototype
__proto__ | Object.getPrototypeOf( )
76
``` function Point(x, y) { this.x = x; this.y = y; } var myPoint = new Point(); ``` WRITE THE REVERSE: myPoint instanceof Point; myPoint instanceof Object
myPoint.__proto__ == Point.prototype | myPoint.__proto__.__proto__ == Object.prototype
77
``` 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
myPoint instanceof Point; | myPoint instanceof Object
78
``` let f = new function () let o = new object () let a = new array (0 ``` ALL in hertiate from:
object.prototype
79
Function objects inherit from ________
Function.prototype.
80
Funtion.protype inherits from
object.prototype
81
to look up the prototype chain we use _______
__proto__
82
with constructor functions we dont need the _____ keyword
return
83
``` function createCircle (radius){ return { radius, draw () { console.log('draw'); } }; } ``` What type of function?
factory
84
____________ is the default toString representation of an object in javascript.
[object Object]
85
Function objects: | stringify(function (){}) ->
[object Function]
86
Array objects: | stringify([]) ->
[object Array]
87
RegExp objects | stringify(/x/) ->
[object RegExp]
88
Date objects | stringify(new Date) ->
[object Date]
89
Object objects! | stringify({}) ->
[object Object]
90
4 pillars (concepts of OOP)
encapsulation abstraction inheritance polymorphism
91
encapsulation does
reduce complexity + increase reusability
92
abstraction
reduce complexity + isolate impact of change | that hides the internal implementation details
93
inheritance
eliminate redundant code
94
polymorphism
refactor switch / case statement
95
What are the 3 Attributes of Object Data Properties?
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
Difference between class and an object?
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
``` typeof Object // ```
'function'
98
``` typeof new Object() // ```
'object'
99
The__________ method is a special method for creating and initializing an object created within a class.
constructor
100
``` function A() {} var a = new A(); console.log(a.constructor); // ```
ƒ A() {}
101
``` function A() {} var a = new A(); console.log(A.constructor); // ```
ƒ Function() { [native code] }
102
Object.prototype.a = 5; ``` var v = {}; console.log(v.a); // ```
5
103
prototype of Object.prototype can be altered TRUE OR FALSE
TRUE