JavaScript Flashcards

1
Q

JavaScript-Primitives-and-Variables

What is the purpose of variables?

A

To store data or information so that we can use those data or information 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 a variable?

A

Write a variable keyword and a variable name. For example, var FullName;

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

Use the equal sign(=) as an assignment operator

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

The name can contain letters, numbers, dollar sign($) or an underscore. But you cannot start with numbers.

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

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

Numbers can be used to calculate, determine the size of the screen, moving the position of an element on a page or setting the amount of time an element should take to fade in.

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, turn switch on or off.

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

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 means that the property has not been defined yet. Whereas, null means that the property has been defined but is empty. Null is intentionally not defined value. For example, null is like a parking lot where you can fill it in later, and undefined is an empty field.

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

Null, String, Number, Boolean, undefined

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

JavaScript-Operator-and-expressions

What data type is returned by an arithmetic operation?

A

Number

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

JavaScript-Operator-and-expressions

What is string concatenation?

A

Combine 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-Operator-and-expressions

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

A

Add one value to another or concatenate strings

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

JavaScript-Operator-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-Operator-and-expressions

What does the += “plus-equals” operator do?

A

It is the additional assignment operator that adds the value of the right operand to a variable and assigns the result to the variable.

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

Associated with information to describe to a group of a lot of information together
The object is to model a real-world object.

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

JavaScript-Objects

What are object properties?

A

Key and value

Variables attached to an object

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

JavaScript-Objects

Describe object literal notation.

A

Variable keyword, variable name, assignment operator, opening curly brace, key and values and closing curly brace.

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

Use the delete keyword. For example, delete hotel.name;

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

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

To store a list of values

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

JavaScript-Arrays

Describe array literal notation.

A

var keyword, variable name, assignment operator, and values in the 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

Array can use an index number to access a specific item

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

Number of items 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

Array.length - 1; Object at lengths of Array -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

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

Function keyword, optional name, zero or more parameters, opening and closing curly braces for the function’s code block, and optional return statement

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

Function’s name and list of arguments surrounded by parenthesis

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

JavaScript-functions

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

A

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

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

JavaScript-functions

What is the difference between a parameter and an argument?

A

A parameter is a placeholder that we don’t know the value of until we call it.
Arguments are the values that are given to the function
Parameters are the local variables.
When we call the function, the parameter becomes an argument.
When we define a function, we declare parameters, and 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-functions

Why are function parameters useful?

A

The parameter can hold the value of the argument until it is called.

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

JavaScript-functions

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

A

The return statement causes the function to produce a value

The return statement exits the function’s code block

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 a 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

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

Math.floor()

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

Math.random()

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

splice()

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

push()

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

Split() method.

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

JavaScript-methods

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

A

No, use console log to find out if string methods changed the original string

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 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 45 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
Is equal to (==), is not equal to (!=), strict equal to (===), strict not equal to (!==), 
Greater than(>), less than (<>, greater than or equal to (>=), less than or 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

The if statement evaluates (or checks) a condition. If the condition evaluates to true, any statements in the subsequent code block are executed.

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

Keyword if, condition opening and code inside the closing curly braces and

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

Logical AND (&&), Logical OR (||), 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 logical operators

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

JavaScript-loops

What is the purpose of a loop?

A

To repeat the similar or the same code over time. To repeat the code without writing it out all ourselves.

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

JavaScript-loops

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

A

To check if the condition is true so that the statement can be executed.

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

JavaScript-loops

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

A

Iteration is the number of times a loop can be executed

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

JavaScript-loops

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

A

An expression is evaluated before each pass through the loop.

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

JavaScript-loops

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

A

An expression or variable declaration is evaluated once before the loop begins.

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

JavaScript-loops

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

A

An expression is evaluated before each loop iteration.

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

JavaScript-loops

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

A

An expression is evaluated at the end of each loop iteration. This occurs before the next evaluation of the condition.

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

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

A

Keyword Break

66
Q

JavaScript-loops

What does the ++ increment operator do?

A

The increment operator adds one to its operand and returns a value

67
Q

JavaScript-loops

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

Debugging mechanism

Look at the data in the code that we are running and test

69
Q

DOM-Querying

Why do we log things to the console?

A

Debugging mechanism

Look at the data in the code that we are running and test

70
Q

DOM-Querying

What is a “model”?

A

copy/duplicate/standard not the actual thing (a representation)
e.g. model plane, model car, model home, model citizen, mental model

71
Q

DOM-Querying

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

A

An HTML document

72
Q

DOM-Querying

What is the word “object” referring to in the phrase Document Object Model?

A

Data type object in JavaScript

Document is the object with all kinds of properties

73
Q

DOM-Querying

What is a DOM Tree?

A

Model of the web page and collection of all elements

74
Q

DOM-Querying

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

A

getElementById() method, querySelector() method

75
Q

DOM-Querying

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

A

querySelectorAll() method

76
Q

DOM-Querying

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

A

Because when you need to work with an element more than once, you should use a variable to store the result of this query.

77
Q

DOM-Querying

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

A

console.dir()

78
Q

DOM-Querying

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

A

The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.

79
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.

80
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.

81
Q

DOM-Events

Why do we log things to the console?

A

To make sure our script is loading properly and to debug and examine values that we use

82
Q

DOM-Events

What is the purpose of events and event handling?

A

To create interactivity in the web page

83
Q

DOM-Events

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

A

No, all parameters are not necessary

84
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

addEventListener

85
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.

86
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.

Event object

87
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

Property of event and where the event occurred
Element that interact with
Use the console to check.

88
Q

DOM-Events

What is the difference between these two snippets of code?

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

A

Note that the parentheses are omitted where the function is called because they would indicate that the function should run as the page loads(rather than when the event fires).

  • event listener does not have return statement because you are calling it.
    element. addEventListener(‘click’, handleClick) is a function definition.
89
Q

DOM-Manipulation

What is the className property of element objects?

A

The className property of the Element interface gets and sets the value of the class attribute of the specified element

90
Q
DOM-Manipulation
How do you update the CSS class attribute of an element using JavaScript?
A

Use the className property ex) variable name.className = value

91
Q

DOM-Manipulation

What is the textContent property of element objects?

A

It represents the text content of the node and its descendants
To set and retrieve the value

92
Q

DOM-Manipulation

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

A

Use the textContent property

ex) Variable name.textContent = value

93
Q

DOM-Manipulation

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

A

No, it mostly used for the form element.

94
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

Complicated.

95
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 organizaiton of code and ability to work and change code effectively
It allows us to show what those clicks are and direct access to it.

96
Q

JavaScript-Forms

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

A

Focus event

97
Q

JavaScript-Forms

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

A

Blur event

98
Q

JavaScript-Forms

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

A

Input event or change event

99
Q

JavaScript-Forms

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

A

Submit event

*Submit event will include all information from all input from the form. But click event doesn’t

100
Q

JavaScript-Forms

What does the event.preventDefault() method do?

A

It prevents the browser from automatically reloading the page with the form’s values in the URL.
Prevent default behavior of that event. preventDefault can be used at any type of event. If you put it in a click handler in anchor tag, it wouldn’t navigate to the page you point to

101
Q

JavaScript-Forms

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

A

Reloads/refreshes the page

102
Q

JavaScript-Forms

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

A

Elements property

103
Q

JavaScript-Forms

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

A

Value property

104
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

You may not understand why it works. It may work by accident. You have two things as wrong but work somehow

105
Q

JavaScript-Forms

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

A

You can see what happens as you code
Everything you make a change, you see what happens.
It helps you understand what is going on.

106
Q

DOM-Creation

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

A

No, It creates an element that can be added to the DOM tree

107
Q

DOM-Creation

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

A

No, It creates an element that can be added to the DOM tree

108
Q

DOM-Creation

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

A

appendChild() method

109
Q

DOM-Creation

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

A

setAttribute(name, value)

110
Q

DOM-Creation

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

A
  1. Create the element node (document.createElement() method)
  2. Give it content (createTextNode())
  3. Query the dom (querySelector() method to add a new element of the selected the element of the parent)
  4. Add it to the DOM (appendChild() method)
111
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.

112
Q
DOM-Creation
Name two ways to set the class attribute of a DOM element.
A

setAttribute method, className property of the object, classList

113
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 reuse the function
  2. We can test the function to see if the DOM tree works
  3. Easily find an error
  4. Easier to navigate
114
Q

DOM-event-delegation

What is the event.target?

A

It returns the element that was triggered by the event.

The element that interacted with and related to the event

115
Q

DOM-event-delegation

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

A

Because the event handler is called during the bubbling or capturing phrase of the event.

116
Q

DOM-event-delegation

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

A

element.tagName property

117
Q

DOM-event-delegation

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

A

It takes a CSS selector as the argument and returns the closest ancestor element or itself, which matches the selector. If there is no such element, null.

118
Q

DOM-event-delegation

How can you remove an element from the DOM?

A

Element.remove() method removes the element from the DOM.

119
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.

If you don’t know the parent element, use the Element.closest() method.

120
Q

JavaScript-View-Swapping

What is the event.target?

A

It returns the element that was triggered by the event.

The element that interacted with and related to the event

121
Q

JavaScript-View-Swapping

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

A

The element will not show on the web page.

It will hide the element. It does remove from the document flow

122
Q

JavaScript-View-Swapping

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

A

It takes a CSS selector string as an argument and returns if the element matches the selector. Otherwise, false. (returns boolean value)

123
Q

JavaScript-View-Swapping

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

A

Element.getAttribute() method.

124
Q

JavaScript-View-Swapping

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

A

Every step.

125
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

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

126
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.

127
Q

JavaScript-and-json

What is JSON?

A

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).

128
Q

JavaScript-and-json

What are serialization and deserialization?

A

Serialization is converting a native object to a string
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 converting a string to a native object
Deserialization is the reverse process: turning a stream of byes into an object in memory

129
Q

JavaScript-and-json

Why are serialization and deserialization useful?

A

Transforming data across network save them to hard drive

We can steam information

130
Q

JavaScript-and-json

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

A

JSON.stringify() method

131
Q

JavaScript-and-json

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

A

JSON.parse() method

132
Q

JavaScript-local-storage

How do you store data in localStorage?

A

Storage.setItem(keyName, keyValue)

133
Q

JavaScript-local-storage

How do you retrieve data from localStorage?

A

Storage.getItem(keyName)

134
Q

JavaScript-local-storage

What data type can localStorage save in the browser?

A

ONLY JSON String

135
Q

JavaScript-local-storage

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

A

The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point.
-Before the user refresh or leave the page

136
Q

JavaScript-custom-methods

What is a method?

A

A method is a function that is a property of an object.

137
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 the property.
  • Method call has 1. Actual data 2. The argument, 3. Name of method
138
Q

JavaScript-custom-methods

Describe method definition syntax (structure).

A

foo: function() {
}
property name: function keyword (parameter(s)) { }
Property name: function keyword parameter in side of parenthesis and curly braces for code block.

139
Q

JavaScript-custom-methods

Describe method call syntax (structure).

A

Object name. Method name (argument)

140
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. The method needs to know where it is coming from.

141
Q

JavaScript-custom-methods

What is the defining characteristic of Object-Oriented Programming?

A

Object-Oriented Programming contains both data (as properties) and behavior (as methods)

142
Q

JavaScript-custom-methods

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

A

Abstraction, Encapsulation, Inheritance, polymorphism

143
Q

JavaScript-custom-methods

A

It is being able to work with complex things in simple ways

144
Q

JavaScript-custom-methods

What does API stand for?

A

Application programming interface

145
Q

JavaScript-custom-methods

What is the purpose of an API?

A

Its purpose is to offer a service to other pieces of software

146
Q

JavaScript-this

What is this in JavaScript?

A

this is the object. this is an implicit parameter of all JavaScript functions

147
Q

JavaScript-this

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

A

It means that it is available in a function code block even though it was never included in the function’s parameter list or declare with var.

148
Q

JavaScript-this

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

A

When the function is called

149
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

Refers to the character object

150
Q

JavaScript-this
Given the above character object, what is the result of the following code snippet? Why?
character.greet();

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

It’s-a-me Mario!, because it calls the greet parameter in the character object. The character object is calling.

151
Q

JavaScript-this
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();

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

It will be It’s-a-me, undefined because the hello has the window object, not the character object. This no longer refers to the character object.

152
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.

153
Q

JavaScript-this

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

A

Find where the function is called and look for an object to the left of the dot.
Finding out which object is calling it.

154
Q

JavaScript-prototype

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based (or prototypal) inheritance

155
Q

JavaScript-prototype

What is a prototype in JavaScript?

A

JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects.

156
Q

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

A

prototype

157
Q

JavaScript-prototype

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

Prototype chain

158
Q

JavaScript-consturctors

What does the new operator do?

A
  1. Creates a blank, plain JavaScript object. For convenience, let’s call it newInstance.
  2. Points newInstance’s [[Prototype]] to the constructor function’s prototype property.
  3. Executes the constructor function with the given arguments, binding newInstance as the this context (i.e. all references to this in the constructor function now refer to newInstance).
  4. If the constructor function returns a non-primitive, this return value becomes the result of the whole new expression. Otherwise, if the constructor function doesn’t return anything or returns a primitive, newInstance is returned instead. (Normally constructors don’t return a value, but they can choose to do so to override the normal object creation process.)
159
Q

JavaScript-consturctors

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

A

prototype property

160
Q

JavaScript-consturctors

What does the instanceof operator do?

A

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