JavaScript Flashcards

1
Q

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

What is the purpose of variables?

A

to store data for the computers to use in the future

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

use a keyword (var, let, const) and variable name and =

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 an equal sign

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

letter, numbers, $, underscore,

numbers cant be first

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

Car= and car= are 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

for storing text that wouldn’t make sense to JavaScript

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

for doing calculations

if the number is a zipcode then store as string

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

it is for letting computers make a decision that is true or false

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

assignment operator

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

by assigning a new value to the variable name without the keyword.

let a = 2; for declaring a variable
a = 5; for updating a variable (no need for keyword)
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
  • null is absents of value intentionally (ex: optional user input)
  • undefined is not trustworthy
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

to know where you’re getting values from. for organization purposes

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

string, number, boolean, null, and undefined

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

a number data

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

glueing strings together

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

addition of numbers and concatination if strings

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

booleans

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

left operand = left operand + right operand

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

to group together data that can represent something

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

JAVASCRIPT-OBJECTS

What are object properties?

A

variables that is glued 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

var obj = { properties: value }

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 as ex: delete object.property or delete 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

dot notation or bracket notation

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

storing values in a grouped list like a grocery list where orders are not essential

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 variable = [ ]

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

objects have individual assigned properties but arrays have automatic number indexes assigned

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

0

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

to find the length of an 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

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

JAVASCRIPT-FUNCTION

What is a function in JavaScript?

A

a reusable block of code

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

JAVASCRIPT-FUNCTION

Describe the parts of a function definition.

A

keyword, optional name, optional number of parameters, code, return

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

JAVASCRIPT-FUNCTION

Describe the parts of a function call.

A

name, ( ) and arguments

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

function call doesnt have keyword function and uses ( ) to call the function

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
parameter = placeholder for potential value 
argument = actual value being placed in the argument
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

pass information to a function, to be able to reuse the function code block

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
1. will replace the function called in that line of code. ex:
function(3) = 10
var x = function(3) will become var x = 10
  1. stops the function entirely once a value is returned
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

to debug our code, to check if our output is as expected, etc

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

JAVASCRIPT-METHODS

What is a method?

A

function that 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

methods have to be called on an object, functions do 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( )

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

pop for last item, shift for first item, splice for specific index

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

JAVASCRIPT-METHODS

How do you append (to the end) 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(‘ ‘)

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

does not change the original string. to check: console.log( )

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

like 50

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

a lot

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 equal, greater than, less than equal, less than, ==, ===

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, true or false

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 let the computer make a decision based on conditions

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

if (conditions) { } else { }

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

&& and || and !

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

&& or ||

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 continuously iterate through a code block until the condition is met

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 know when to stop the loop

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 = looping through once

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

at the start of every 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

before the loop begins and only once

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

before each 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

after each iteration

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

break

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

JAVASCRIPT-LOOPS

What does the ++ increment operator do?

A

increments by 1

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

JAVASCRIPT-LOOPS

How do you iterate through the keys of an object?

A

for in loop

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

DOM-QUERYING

Why do we log things to the console?

A

to see what we’re doing and for debugging

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

DOM-QUERYING

What is a “model”?

A

a representation of something

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

DOM-QUERYING

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

A

the html document

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

DOM-QUERYING

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

A

data type

72
Q

DOM-QUERYING

What is a DOM Tree?

A

representative chunk of the page that shows the element and their element’s configuration

DOM = model that represents an html document in the form of javascript data types

73
Q

DOM-QUERYING

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

A

document. querySelector( )

document. getElementById( )

74
Q

DOM-QUERYING

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

A

document.querySelectorAll( )

75
Q

DOM-QUERYING

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

A

to be able to use it again in the future

76
Q

DOM-QUERYING

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

A

console.dir( )

77
Q

DOM-QUERYING

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

A

html loads from top to bottom and the elements need to load first

78
Q

DOM-QUERYING

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

A

a css selector and returns first one that matches

79
Q

DOM-QUERYING

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

A

a css selector and returns a NodeList

80
Q

DOM-EVENTS

Why do we log things to the console?

A

in this exercise, to debug and check if action happened

81
Q

DOM-EVENTS

What is the purpose of events and event handling?

A
  • something that happens

- to set up a list of action whenever an event occurs

82
Q

DOM-EVENTS

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

A

no, 3rd parameter of addEventListener is optional

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

addEventListener

84
Q

DOM-EVENTS

What is a callback function?

A

a function that is called as an argument in another function

85
Q

DOM-EVENTS

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

A
  • object that is built in the moment as a reference of data
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 button that you interact with
    • target = the dom element where the event originated from
  • console.log(event.target);
  • in the browser’s console
87
Q

DOM-EVENTS

What is the difference between these two snippets of code?

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

A

2nd one always gets called without having to click it??

88
Q

DOM-MANIPULATION

What is the className property of element objects?

A

property that can get or set the value of class attribute

89
Q

DOM-MANIPULATION

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

A

use the className property on an element

select your element.className = new value

90
Q

DOM-MANIPULATION

What is the textContent property of element objects?

A

get or set a text element

91
Q

DOM-MANIPULATION

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

A

select your element.textContent = ‘whatever’

92
Q

DOM-MANIPULATION

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

A

no, if it’s not necessary, then no need

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 if we did not have variable

94
Q

DOM-MANIPULATION

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

A

makes it easier to know what’s going on in your own code. store it in javascripts in variables and use that data to influence the DOM.

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 form?

A

submit

99
Q

JAVASCRIPT-FORMS

What does the event.preventDefault() method do?

A

stops the default behavior from happening or in this form case = browsers from refreshing

100
Q

JAVASCRIPT-FORMS

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

A

the page will refresh because of the action attribute (outdated)

101
Q

JAVASCRIPT-FORMS

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

A

elements property

102
Q

JAVASCRIPT-FORMS

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

A

value

103
Q

JAVASCRIPT-FORMS

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

A

wont be able to see if your code works

104
Q

JAVASCRIPT-FORMS

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

A

can check to see if your code works as you’re working on it

105
Q

DOM-CREATION

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

A

no, still have to append it

106
Q

DOM-CREATION

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

A

appendChild method

107
Q

DOM-CREATION

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

A

setAttribute(attribute, value)

108
Q

DOM-CREATION

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

A
var h1 = document.createElement('h1')
someDiv.appenchild(h1)
109
Q

DOM-CREATION

What is the textContent property of an element object for?

A

to get or set text content

110
Q

DOM-CREATION

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

A
  • someElement.className = ‘classssss’

- setAttribute (‘className’, ‘classVaues’)

111
Q

DOM-CREATION

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

A
  • saves a lot of time

- makes it reusable

112
Q

DOM-EVENT-DELEGATION

What is the event.target?

A

where the event originated from

113
Q

DOM-EVENT-DELEGATION

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

A

event bubbling

114
Q

DOM-EVENT-DELEGATION

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

A

event.target.tagName

115
Q

DOM-EVENT-DELEGATION

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

A

closest CSS selector and matches with closest ancestor (parent) element

116
Q

DOM-EVENT-DELEGATION

How can you remove an element from the DOM?

A

someElement.remove( )

117
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

addEventListener to the parent element, use tagName method to check if you’re targeting the right element

118
Q

JAVASCRIPT-VIEW-SWAPPING

What is the event.target?

A

where the event originated from

119
Q

JAVASCRIPT-VIEW-SWAPPING

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

A

it will hide the element from the viewer

120
Q

JAVASCRIPT-VIEW-SWAPPING

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

A

css selectors and returns a boolean value

121
Q

JAVASCRIPT-VIEW-SWAPPING

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

A

call it on the dom element

122
Q

JAVASCRIPT-VIEW-SWAPPING

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

A

every step

123
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

have to add event listener for each individual element

124
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

have to write many conditional statements

125
Q

JAVASCRIPT-AND-JSON

What is JSON?

A

JavaScript Object Notation and lets us store them that is not in memory space

126
Q

JAVASCRIPT-AND-JSON

What are serialization and deserialization?

A
  • stringifying and parsing data for network transmission

- breaks up data to put them into 1 sequence from beginning to end to be able to transmit

127
Q

JAVASCRIPT-AND-JSON

Why are serialization and deserialization useful?

A

breaks down data to byte size and easy to transmit data and load data throughout the web and store data

128
Q

JAVASCRIPT-AND-JSON

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

A

use JSON.parse(someJSONString)

returns an array or object

129
Q

JAVASCRIPT-LOCAL-STORAGE

How do you store data in localStorage?

A

localStorage.setItem( keyName , keyValue )

130
Q

JAVASCRIPT-LOCAL-STORAGE

How do you retrieve data from localStorage?

A

localStorage.getItem( keyName )

131
Q

JAVASCRIPT-LOCAL-STORAGE

What data type can localStorage save in the browser?

A

-strings

132
Q

JAVASCRIPT-LOCAL-STORAGE

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

A
  • is fired when the window, the document and its resources are about to be unloaded.
133
Q

JAVASCRIPT-CUSTOM-METHODS

What is a method?

A

method is a function of a property

134
Q

JAVASCRIPT-CUSTOM-METHODS

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

A
  • a method definition is an anonymous function of the value of a property
  • method call is property.method (parameter)
135
Q

JAVASCRIPT-CUSTOM-METHODS

Describe method definition syntax (structure).

A
var object = {
     methodName: function (parameters) {
           function block code
           return something;
     }
};
136
Q

JAVASCRIPT-CUSTOM-METHODS

Describe method call syntax (structure).

A

object.method(parameters)

137
Q

JAVASCRIPT-CUSTOM-METHODS

How is a method different from any other function?

A

it’s not.

138
Q

JAVASCRIPT-CUSTOM-METHODS

What is the defining characteristic of Object-Oriented Programming?

A

it’s a concept based on objects which contain data (known as attributes or properties) and code (known as methods)

139
Q

JAVASCRIPT-CUSTOM-METHODS

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

A

Abstraction, encapsulation, inheritance, polymorphism

140
Q

JAVASCRIPT-CUSTOM-METHODS

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways.

141
Q

JAVASCRIPT-CUSTOM-METHODS

What does API stand for?

A

Application Programming Interface

142
Q

JAVASCRIPT-CUSTOM-METHODS

What is the purpose of an API?

A

connects computers to computer programs

143
Q

JAVASCRIPT-THIS

What is ‘this’ in JavaScript?

A

‘this’ refers to the current object being worked on currently

144
Q

JAVASCRIPT-THIS

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

A

can use ‘this’ even though it is not listed as a parameter (which shouldnt have a parameter named ‘this’)

145
Q

JAVASCRIPT-THIS

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

A

call time

146
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

since greet function is never called, the value of ‘this’ is nothing since ‘this’ only gets a value when something is called.

147
Q

JAVASCRIPT-THIS

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

character.greet();

A

It’s a me, Mario.

148
Q

JAVASCRIPT-THIS

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

var hello = character.greet;
hello();
A

it’s a me ‘undefined’

- because ‘this’ only refers to the object from the left of the dot and nothing

149
Q

JAVASCRIPT-THIS

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

A

we dont know yet until it is called

150
Q

JAVASCRIPT-THIS

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

A

it would be the object that it is working with (object to the left of the dot)

151
Q

JAVASCRIPT-PROTOTYPES

What kind of inheritance does the JavaScript programming language use?

A

prototype based

152
Q

JAVASCRIPT-PROTOTYPES

What is a prototype in JavaScript?

A
153
Q

JAVASCRIPT-PROTOTYPES

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

in the prototype

155
Q

JAVASCRIPT-CONSTRUCTOR

What does the new operator do?

A

The new operator lets developers create an instance of a object

  • 4 steps that the new operator will take
    • create a black, plain JS object
    • Points new Instances to the constructor function’s prototype property
    • ‘this’ will now be the new object
    • if you do not return anything(99.99% wont return anything) then object is returned instead
156
Q

JAVASCRIPT-CONSTRUCTOR

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

A

prototype property

157
Q

JAVASCRIPT-CONSTRUCTOR

What does the instanceof operator do?

A

check whether an object is an instance of a particular class or not.

158
Q

JAVASCRIPT-TIMERS

What is a “callback” function?

A

a function passed into another function as an argument

159
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, timeInMiliseconds)

160
Q

JAVASCRIPT-TIMERS

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

A

setInterval(function, imeInMiliseconds)

161
Q

JAVASCRIPT-TIMERS

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

A

0

162
Q

JAVASCRIPT-TIMERS

What do setTimeout() and setInterval() return?

A
163
Q

HTTP-MESSAGES

What is a client?

A

a desktop computer or workstation that is capable of obtaining information and applications from a server.

a program that is requesting data

164
Q

HTTP-MESSAGES

What is a server?

A

A server is a computer program or device that provides a service to another computer program and its user, also known as the client.

165
Q

HTTP-MESSAGES

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET

166
Q

HTTP-MESSAGES

What three things are on the start-line of an HTTP request message?

A

HTTP method, the request-target (website) and what version

ex:
GET / google.com / 1.0

167
Q

HTTP-MESSAGES

What three things are on the start-line of an HTTP response message?

A

a start line describing the message, a block of headers containing attributes, and an optional body containing data.

protocol version, status code, status text

168
Q

HTTP-MESSAGES

What are HTTP headers?

A

a field of an HTTP request or response that passes additional context and metadata about the request or response. For example, a request message can use headers to indicate it’s preferred media formats, while a response can use header to indicate the media format of the returned body.

169
Q

HTTP-MESSAGES

Where would you go if you wanted to learn more about a specific HTTP Header?

A

mdn

170
Q

HTTP-MESSAGES

Is a body required for a valid HTTP request or response message?

A

no

171
Q

JAVASCRIPT-AJAX

What is AJAX?

A

an application that allows you to update 1 part of the website without having to reload the entire page

172
Q

JAVASCRIPT-AJAX

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

173
Q

JAVASCRIPT-AJAX

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest

174
Q

JAVASCRIPT-AJAX

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

‘load’ event

175
Q

JAVASCRIPT-AJAX

Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

prototypal inheritence