JavaScript Flashcards

1
Q

JavaScript Primitives and Variables

What is the purpose of variables?

A

To store data so that we can go back to variables later

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

JavaScript Primitives and Variables

How do you declare variable?

A

Create the variable name and give it a name.

Ex) var name

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

JavaScript Primitives and Variables

How do you initialize (assign a value to) a variable?

A

The equal sign (=) is an assignment operator. It says that you are going to assign a value to the variable. It also used to update the value given to a variable

ex) var keyword variable name = value

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

JavaScript Primitives and Variables

What characters are allowed in variable names?

A

A letter, dollar sign($) or an underscore(_). It must not start with a number

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

JavaScript Primitives and Variables

What does it mean to say that variable names are “case sensitive”?

A

-If two variables are the same words but one has upper-case and other one has lower-case, it becomes different variables.

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

JavaScript Primitives and Variables

What is the purpose of a string?

A

Strings can be used when working with any kind of text.

storage for characters

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

JavaScript Primitives and Variables

What is the purpose of a number?

A

To count or calculate sums and store numeric values

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

JavaScript Primitives and Variables

What is the purpose of a boolean?

A

To make decisions. For example, yes or no

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

JavaScript Primitives and Variables

What does the = operator mean in JavaScript?

A

It is assignment operator. Assign value to the variable

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

JavaScript Primitives and Variables

How do you update the value of a variable?

A

Assign new variable value

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

JavaScript Primitives and Variables

What is the difference between null and undefined?

A

Undefined is empty for some reason but we don’t know why it is empty. Undefined is a computer (JavaScript) saying nothing. cannot tell which said undefined.

  • Null is assigned by humans, not JavaScript.
  • Null is an empty value that needs to be assigned at some point. It made the empty on purpose to put values later.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

JavaScript Primitives and Variables

Why is it a good habit to include “labels” when you log values to the browser console?

A

Help others and myself where these values are coming from. Benefit others and yourself in the future

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

JavaScript Primitives and Variables

Give five examples of JavaScript primitives

A

Undefined, null, number, string, boolean

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

JavaScript Operators and Expressions

What data type is returned by an arithmetic operation?

A

Numeric/Number

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

JavaScript Operators and Expressions

What is string concatenation?

A

Join two or more strings to create one new string

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

JavaScript Operators and Expressions

What purpose(s) does the + plus operator serve in javaScript?

A

Add one value to another

The additional operator (+) produces the sum of numeric operands or string concatenation.

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

JavaScript Operators and Expressions

What data type is returned by comparing two values(, ===, etc)?

A

boolean

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

JavaScript Operators and Expressions

What does the += ‘plus-equals’ operator do?

A

Value on the right side added to the left variable, and then get new value.

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

JavaScript Objects

What are objects used for?

A

Group of data and functionality.

Data type to store further data with individual properties.

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

JavaScript Objects

What are object properties?

A

Individual key correlates with value

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

JavaScript Objects

Describe object literal notation

A

opening and closing curly braces

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

JavaScript Objects

How do you remove a property from an object?

A

Delete operator and name of object.property

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

JavaScript Objects

What are the two ways to get or update the value of a property?

A

To update the value of properties, use dot notation or square brackets.

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

JavaScript Arrays

What are arrays used for?

A

list of data

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

JavaScript Arrays

Describe array literal notation

A

opening and closing square brackets.

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

JavaScript Arrays

How are arrays different from “plain” objects?

A

An Array does not need an individually named key. Only numbers.
Objects can have numbers and letters
The array is made with property length.
The array counts the total number of items.
Object has to state the name directly.
The Array can use unshift, push method to interact

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

JavaScript Arrays

What number represents the first index of an array?

A

Zero

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

JavaScript Arrays

What is the length property of an array?

A

Holds the number of items in the array

Tells you how many items are in the array

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

JavaScript Arrays

How do you calculate the last index of an array?

A

Object at lengths of Array -1 ex) students[length of Array -1] -> student[array.length -1]

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

JavaScript Functions

What is a function in JavaScript?

A
  • A set of statements that perform a task or calculate a value
  • Functions are objects that are reusable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

JavaScript Functions

Describe the parts of a function definition.

A

The function keyword, the name of function, a list of parameters to the function, enclosed in parenthesis and separated by commas, and the JavsScript statements that define function, enclosed in curly braces { }.

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

JavaScript Functions

Describe the parts of a function call.

A

Write the name of the function and zero or more arguments with a comma surrounded by parenthesis ().

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

JavaScript Function

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

When a function is called, the parameters in its definition take on the value of the arguments that were passed.

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

JavaScript Function

What is the difference between a parameter and an argument?

A

A parameter is like a placeholder.
When considering an actual “call” to the function, it becomes an argument.
-When we define a function, we declare parameters and that when we call a function, we pass it arguments.

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

JavaScript Function

Why are function parameters useful?

A

The parameter can hold the value of the argument until it is called.
Varying results based on data we give. The parameter is reusable.

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

JavaScript Function

What two effects does a return statement have on the behavior of a function?

A

Cause the function to produce a value we can use in our program
Prevents any more code in the function’s code block from being run. (Exit the function; no code after the return statement is executed.)

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

JavaScript - Methods

Why do we log things to the console?

A

The console is a debugging tool where the browser prints error and warnings as they occur in JavaScript code. (debugging mechanism)

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

JavaScript - Methods

What is a method?

A

A method is a function which is a property of an object

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

JavaScript - Methods

How is a method different from any other function?

A

The method is associated with an object while other function is not.

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

JavaScript - Methods

How do you remove the last element from an array?

A

the pop() method

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

JavaScript - Methods

How do you round a number down to the nearest integer?

A

the math.floor() method

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

JavaScript - Methods

How do you generate a random number?

A

the math.random() method

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

JavaScript - Methods

How do you delete an element from an array?

A

the splice() method

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

JavaScript - Methods

How do you append an element to an array?

A

the push() method

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

JavaScript - Methods

How do you break a string up into an array?

A

the split() method

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

Do string methods change the original string? How would you check if you weren’t sure?

A

No. String is immutable so it would not change. Inspect your value using console.log to check if you are not sure.

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

JavaScript - Methods

Roughly how many string methods are there according to the MDN Web docs?

A

Around 45

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

JavaScript - Methods

Is the return value of a function or a method useful in every situation?

A

No

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

JavaScript - Methods

Roughly how many array methods are there according to the MDN Web docs?

A

Around 40 to 50

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

JavaScript - Methods

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

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

JavaScript - if

Give 6 examples of comparison operators

A

Greater than (>), less than (=), less than or equal to (<=), is equal to (==), is not equal to (!=), strictly equal to (===), strict not equal to (!==),

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

JavaScript-if

What data type do comparison expressions evaluate to?

A

Boolean

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

JavaScript-if

What is the purpose of an if statement?

A

To evaluate or check a condition and make decisions.

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

JavaScript-if

Is else required in order to use an if statement?

A

No

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

JavaScript-if

Describe the syntax (structure) of an if statement.

A

KEY word if, condition, Opening curly brace ({), code to execute if value is true, closing curly brace(}).

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

JavaScript-if

What are the three logical operators?

A

The logical AND (&&), logical OR (||) and logical NOT (!)

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

JavaScript-if

How do you compare two different expressions in the same condition?

A

Use the logical operators

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

JavaScript-loop

What is the purpose of a loop?

A

To repeat the similar or the same code over time and to repeat the code without writing out all ourself

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

JavaScript-loop

What is the purpose of a condition expression in a loop?

A

Stop to not fall into the infinity loop

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

JavaScript-loop

What does “iteration” mean in the context of loops?

A

How many times the loop will go through

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

JavaScript-loop

When does the condition expression of a while loop gets evaluated?

A

before each iteration

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

JavaScript-loop

When does the initialization expression of a for loop gets evaluated?

A

An expression or variable declaration that evaluated once before the loops begin.

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

JavaScript-loop

When does the condition expression of a for loop gets evaluated?

A

An expression to be evaluated before each loop iteration. If it evaluates to true, statement is executed. If it is false, the loop stops

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

JavaScript-loop

When does the final expression of a for loop gets evaluated?

A

An expression to be evaluated at the end of each loop iteration. After the code block runs. before condition runs again.

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

JavaScript-loop

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

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

JavaScript-loop

What does the ++ increment operator do?

A

The increment operator (++) increments (adds one to) its operand and returns a value.

67
Q

JavaScript-loop

How do you iterate through the keys of an object?

A

for-in loop

68
Q

Dom-querying

Why do we log things to the console?

A

To debug and examine values that we use

69
Q

Dom-querying

What is a “model”?

A

Replicate, recreation of something else.

70
Q

Dom-querying

Which “document” is being referred to in the phrase Document Object Model?

A

An HTML document

71
Q

Dom-querying

What is the word ‘object’ referring to in the phrase Document Object Model?

A

Data type object in JavaScript

72
Q

Dom-querying

What is a DOM Tree?

A

DOM tree has parent elements, child elements and nods.

73
Q

Dom-querying

Give two examples of document methods that retrieve a single element from the DOM

A

getElementById() and querySelector();

74
Q

Dom-querying

Give one example of a document method that retrieves multiple elements from DOM at once.

A

querySelectorAll()

75
Q

Dom-querying

Why might you want to assign the return value of a DOM query to a variable?

A

You can access it again. Reuse that reference later.

76
Q

Dom-querying

What console method allows you to inspect the properties of a DOM element object?

A

The directory method - console.dir()

77
Q

Dom-querying

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

It gives the HTML time to load before any of the JavaScript loads, which can prevent errors, and speed up website response time.
JavaScript would run first and the body element would not show up

78
Q

Dom-querying

What does document.querySelector() take. as its argument and what does it return?

A

querySelector() takes CSS selector as the only argument and returns the first Element within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned.

79
Q

Dom-querying

What does document.querySelectorAll() take as its argument and what does it return?

A

querySelectorAll() Takes CSS selector as the only argument and returns a static (not live) NodeList representing a list of the document’s elements that match the specified group of selectors.

80
Q

DOM-Events

Why do we log things to the console?

A
  • To make sure our script is loading properly

- debug and examine values that we use

81
Q

DOM-Events

What is the purpose of events and event handling?

A

Create interactivity in the webpage (user driven)

82
Q

DOM-Events

Are all possible parameters required to use a JavaScript method or function?

A

No, all parameters are not necessary

83
Q

DOM-Events

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

EventListener

84
Q

DOM-Events

What is a callback function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

85
Q

DOM-Events

What object is passed into an event listener callback when the event fires?

A

Object with all data about event just occurred.

86
Q

DOM-Events

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

The event.target is the target property of the event object where the event occurred. If you are not sure, use console.log to check.

87
Q

DOM-Events

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

EventListener does not have return statement because you are calling it. What is return if we don’t have return statement written? undefined. handleClick() will get call immediately with undefined return value. element.addEventListener(‘click’, handleClick) is function definition.

88
Q

DOM-Manipulation

What is the className property of element objects?

A

It is holding the value to get current value or assign a new value

89
Q

DOM-Manipulation

How do you update the CSS class attribute of an element using JavaScript?

A

Document.querSelector for element.className = new value

90
Q

DOM-Manipulation

What is the textContent property of element objects?

A

Property that holds in that element and its child elements

91
Q

DOM-Manipulation

How do you update the text within an element using JavaScript?

A

Select argument using query, get what value is and assign to the value that you query for

92
Q

DOM-Manipulation

Is the event parameter of an event listener callback always useful?

A

No, because we don’t need it sometimes.

93
Q

DOM-Manipulation

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

More complicated. JavaScript function should rely to store data not on DOM elements

94
Q

DOM-Manipulation

Why is storing information about a program in variables better than only storing it in the DOM?

A

It is easier for JavaScript to work with more efficient organization of code and ability to work and change code effectively

95
Q

JavaScript-Forms

What event is fired when a user places their cursor in a form control?

A

Focus event

96
Q

JavaScript-Forms

What event is fired when a user’s cursor leaves a form control?

A

Blur event

97
Q

JavaScript-Forms

What event is fired as a user changes the value of a form control?

A

Input event

98
Q

JavaScript-Forms

What event is fired when a user clicks the “submit” button within a ?

A

Submit event

99
Q

JavaScript-Forms

What does the event.preventDefault() method do?

A
The preventDefault() method is action of event.
Prevent browsers from reloading the page
ex) Default behavior of prevent default is not allowing the checkbox to be checked.
100
Q

JavaScript-Forms

What does submitting a form without event.preventDefault() do?

A

Reloads/refreshes the page

101
Q

JavaScript-Forms

What property of a form element object contains all of the form’s controls.

A

Element property

102
Q

JavaScript-Forms

What property of a form control object gets and sets its value?

A

Value property

103
Q

JavaScript-Forms

What is one risk of writing a lot of code without checking to see if it works so far?

A

You want to know you are actually making progress. No way to find out what went wrong. *Do everything one minor step at a time

104
Q

JavaScript-Forms

What is an advantage of having your console open when writing a JavaScript program?

A

You can see what happens as you code

105
Q

Dom-Creation

Does the document.createElement() method insert a new element into the page?

A

No, it only creates elements. It does not make elements visible. Users look at the DOM in a webpage.

106
Q

Dom-Creation

How do you add an element as a child to another element?

A

The appendChild() method

107
Q

Dom-Creation

What do you pass as the arguments to the element.setAttribute() method?

A

Name means name of attribute. Value means value of attribute.

108
Q

Dom-Creation

What steps do you need to take in order to insert a new element into the page?

A

Create the element node (document.createElement() method)
Give it content (createTextNode())
Query the dom (querySelector() method to add a new element of the selected the element of the parent)
Add it to the DOM (appendChild() method)

109
Q

Dom-Creation

What is the textContent property of an element object for?

A

To read the text context of the element OR assign new text to the element.

110
Q

Dom-Creation

Name two ways to set the class attribute of a DOM element.

A
  1. SetAttribute method, querySelector for

2. Assign string to className property of the object

111
Q

Dom-Creation

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A
  1. We can test the function to see the DOM Tree

2. Reuse the code for easily.

112
Q

DOM - Event - Delegation

What is the event.target?

A

The event.target is the target property of the event object. where the event occurred. Return the element that triggered by event.

113
Q

DOM-Event-Delegation

What is the event.target?

A

The event.target is the target property of the event object. where the event occurred. If you are not sure, use console.log to check.
Return the element that triggered by event.

114
Q

DOM-Event-Delegation

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

Bubbling

115
Q

DOM-Event-Delegation

What DOM element property tells you what type of element it is?

A

element.tagName

116
Q

DOM-Event-Delegation

What does the element.closest() method take as its argument and what does it return?

A

The element.closest() method takes CSS selector string as its argument and returns itself or the matching ancestor. If no such element exists, it returns null.

117
Q

DOM-Event-Delegation

How can you remove an element from the DOM?

A

Element.remove();

118
Q

DOM-Event-Delegation

If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

The event delegation allows you to avoid adding event listeners to specific nodes; instead, the event listener is added to one parent. Add the event listener to the parent element (ex: UL). But if you add the event listener to the parent, how will you know which element was clicked? Simple: when the event bubbles up to the UL element, you check the event object’s target property to gain a reference to actual clicked node.

119
Q

JavaScript - view-swapping

What is the event.target?

A

Return the element that triggered the event.

120
Q

JavaScript - view-swapping

What is the affect of setting an element to display: none?

A

When you set the value of display to none, the affected element will disappear. This means the element will no longer take up any space on the web page.
-Remove from document flow. Does not exist entirely.

121
Q

JavaScript - view-swapping

What does the element.matches() method take as an argument and what does it return?

A

It takes CSS selector string as an argument and returns the result in Boolean value

122
Q

JavaScript - view-swapping

How can you retrieve the value of an element’s attribute?

A

getAttribute method

123
Q

JavaScript - view-swapping

At what steps of the solution would it be helpful to log things to the console?

A

All the time

124
Q

JavaScript - view-swapping

If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?

A

Withouout event delegation, we would have to write individual custom event handler for tab. We would have to have querySelector for every element we want to target on. If we don’t have event flow, we cannot do event delegation

125
Q

JavaScript - view-swapping

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

Write new if statements for every single element.

126
Q

JavaScript and JSON

What is JSON?

A

JSON is an extremely common data interchange format used to send and store information in computer systems. Turn into a string and turn back to object.

127
Q

JavaScript and JSON

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or sent it over the network.
Deserialization is the reverse process: turning a stream of bytes into an object in memory.

128
Q

JavaScript and JSON

Why are serialization and deserialization useful?

A

Transmitting data across network save them to hard drive

129
Q

JavaScript and JSON

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

130
Q

JavaScript and JSON

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse()

131
Q

JavaScript Local Storage

How do you store data in localStorage?

A

Use Storage.setItem(key, value)

132
Q

JavaScript Local Storage

How do you retrieve data from localStorage?

A

storage.getItem(key name)

133
Q

JavaScript Local Storage

What data type can localStorage save in the browser?

A

ONLY string

134
Q

JavaScript Local Storage

When does the ‘beforeunload’ event fire on the window object?

A

Before the user refresh or leave the page

135
Q

JavaScript-custom-methods

What is a method?

A

A method is a function which is a property of an object.
A method in object-oriented programming (OOP) is a procedure associated with a message and an object. An object consists of data and behavior; these compose an interface, which specifies how the object may be utilized by any of its various consumers.

136
Q

JavaScript-custom-methods

How can you tell the difference between a method definition and a method call?

A
  • Method definition has: 1. Function keyword 2. function code block, 3, function is being assigned to property.
  • Method call has: 1. Actual data 2. Argument, 3. Name of method
137
Q

JavaScript-custom-methods

Describe method definition syntax (structure).

A

foo: function() {
}
property name: function keyword (parameter(s)) { code block }

138
Q

JavaScript-custom-methods

Describe a method call syntax (structure).

A

Object . method name (argument)

139
Q

JavaScript-custom-methods

How is a method different from any other function?

A

Function — a set of instructions that perform a task.
Method — a set of instructions that are associated with an object.
Method stores inside the object. Method needs to know where it is coming from.

140
Q

JavaScript-custom-methods

What is the defining characteristic of Object-Oriented Programming?

A

Object-Oriented Programing contains both data (as properties) and behaviors (as methods)

141
Q

JavaScript-custom-methods

What are the four “principles” of Object-Oriented Programming?

A

Abstraction, encapsulation, inheritance, polymorphism

142
Q

JavaScript-custom-methods

What is “abstraction”?

A

Being able to work with possible complex things in simple ways.

143
Q

JavaScript-custom-methods

What does API stand for?

A

Application Programming Interface

144
Q

JavaScript-custom-methods

What is the purpose of an API?

A

An API (Application Programming Interface) is a set of features and rules that exist inside a software program (the application) enabling interaction with it through software - as opposed to a human user interface. The API can be seen as a simple contract (the interface) between the application offering it and other items, such as third party software or hardware.

145
Q

JavaScript-This

What is this in JavaScript?

A

This is an implicit parameter of all JavaScript functions
This is a variable that object you are currently working on. In most cases, the value of this is determined by how a function is called (runtime binding). It can’t be set by assignment during execution, and it may be different each time the function is called.

146
Q

JavaScript-This

What does it mean to say that this is an “implicit parameter”?

A

it’s an implicit parameter, meaning that it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var. We don’t have to state a variable in a parameter.

147
Q

JavaScript-This

When is the value of this determined in a function; call time or definition time?

A

call time

148
Q

JavaScript-This

What does this refer to in the following code snippet?
var character = {
                 firstName: 'Mario',
  		    greet: function () {
    		    var message = 'It\'s-a-me, ' + this.firstName + '!';
    		    console.log(message);
  }
  };
A

Method is not being called so there is nothing.

149
Q

JavaScript-This

Given the character object, what is the result of the following code snippet? Why?

var character = {
                 firstName: 'Mario',
  		    greet: function () {
    		    var message = 'It\'s-a-me, ' + this.firstName + '!';
    		    console.log(message);
  }
  };
character.greet();
A

It’s-a-me Mario! //Why? Because the method is invoked(called) of character object.

150
Q

JavaScript-This

var character = {
                 firstName: 'Mario',
  		    greet: function () {
    		    var message = 'It\'s-a-me, ' + this.firstName + '!';
    		    console.log(message);
  }
  };
var hello = character.greet;
 hello();
A

The result is “It’s-a-me undefined”

Here, hello has the window object not the character object.

151
Q

JavaScript-This

How can you tell what the value of this will be for a particular function or method definition?

A

You don’t know until the method is called. You cannot see the function being called, then you do not know what the value of this will be.

152
Q

JavaScript-This

How can you tell what the value of this is for a particular function or method call?

A

The value of this can be recognized as “the object to the left of the dot” when the function is called (as a method)

153
Q

JavaScript-Prototypes

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based (or prototypal) inheritance

154
Q

JavaScript-Prototypes

What is a prototype in JavaScript?

A

Prototypes are the mechanism by which JavaScript objects inherit features from one another. Object that other object can build upon.

155
Q

JavaScript-Prototypes

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?

A

Prototype
Every object in JavaScript has a built-in property, which is called its prototype. The prototype is itself an object, so the prototype will have its own prototype, making what’s called a prototype chain. The chain ends when we reach a prototype that has null for its own prototype.

156
Q

JavaScript-Prototypes

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

Look in the prototype object of object’s name.

Use the function Object.getPrototypeOf():

157
Q

JavaScript-constructors

What does the new operator do?

A

The new operator let developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function

158
Q

JavaScript-constructors

What property of JavaScript functions can store shared behavior for instances created with new?

A

Prototype property

159
Q

JavaScript-constructors

What does the instanceof operator do?

A

The instanceof operator tests to see if the prototype property of a construction appears anywhere in the prototype chain of an object. The return value is a boolean value;

160
Q

JavaScript-timers

What is a “callback” function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

161
Q

JavaScript-timers

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

setTimeout() function

162
Q

JavaScript-timers

How can you set up a function to be called repeatedly without using a loop?

A

setInterval() function

163
Q

JavaScript-timers

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0

164
Q

JavaScript-timers

What do setTimeout() and setInterval() return?

A

Numeric value for ID.