JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Variable is a container for a value, like a number we might use in a sum, or a string that we might use as a part of a sentence.

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

How do you declare a variable?

A

We type the keyword (var, let, const) followed by the name you want to call your variable.

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

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

A

First type the variable name, followed by the equals sign(=), followed by the value you want to give it.

Example: var firstName = ‘Dylan’;

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

What characters are allowed in variable names?

A

letters, numbers (cannot start with a number!) dollar sign($), or an underscore

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

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

A

Variable names care about the case sensitivity of their names, meaning a variable named score and Score would be different because of the capitalization of the letter S in score.

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

What is the purpose of a string?

A

Strings are pieces of text, they must be wrapped within quote marks.

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

What is the purpose of a number?

A

calculating numbers, doing math stuff

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

What is the purpose of a boolean?

A

True or False values, they are generally used to test a condition, after which code is run as appropriate.

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

What does the = operator mean in JavaScript?

A

1 equal sign is used for assignment of variables

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

How do you update the value of a variable?

A

Once the variable has been initialized, you can change (or update) that value by giving it a different value.

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

What is the difference between null and undefined?

A

Null means empty can only be assigned, undefined means a variable is declared but has no actual arguments.

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

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

A

A label in the console.log is a simple way to describe the variable or value being logged.

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

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

What data type is returned by an arithmetic operation?

A

single numerical value (number)

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

What is string concatenation?

A

the process of appending one string to the end of another string and so on.

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

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

A
  • addition in math

- string concatenation

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

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

A

boolean ( true or false )

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

What does += “plus equals” operator do?

A

+= or “plus-equals” adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator.

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

What are objects used for?

A

It is used to store various keyed collections and more complex entities

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

What are object properties?

A

Properties are the values associated with a JavaScript object.

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

Describe the object literal notation:

A

The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array. Values created with anonymous functions are methods of your object.

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

How do you remove a property from an object?

A

delete operator

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

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

A

dot notation and bracket notation

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

What are arrays used for?

A

Storing a collection of multiple items under a single variable name

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

Describe the array literal notation:

A

var arrayName = [ ];

separate indexes by commas

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

How are arrays different from “plain” objects?

A

Arrays have an order, stored within square brackets, have numeric indexes

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

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

What is the length property of an array?

A

returns the length of the array (counts each index and returns number value)

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

How do you calculate the last index of an array?

A

var variableName = array[array.length - 1]

subtract 1 from length of the array

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

Describe the parts of a function definition:

A
function (keyword) optionalName(parameters){
                    (code)
      return
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Describe the parts of a function call

A

functionName(arguments,arguments);

-arguments are optional

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

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

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

What is the difference between a parameter and an argument?

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

Why are function parameters useful?

A

they provide placeholders when writing code

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

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

A

1) it exits the functions code block

2) it gives back a value

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

Why do we log things to the console?

A

console.log is a debugging tool to check for errors

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

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
38
Q

How is a method different from any other function?

A
  • methods are functions

- methods are attached to an object

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

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
40
Q

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
41
Q

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
42
Q

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
43
Q

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
44
Q

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
45
Q

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

A

They remain the same unless you assign it to a new variable. You can check by console.log()

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

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

A

around 30 string methods

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

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
48
Q

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

A

around 25 array methods

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

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
50
Q

Give 6 examples of comparison operators:

A
Is Equal to (==) 
is not equal to (!=)
Greater than (>)
Less than (=)
Less than or equal to (<=)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

What data type do comparison expressions evaluate to?

A

Booleans (true or false)

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

What is the purpose of an IF statement?

A

If statement is a decision-making statement that guides a program to make decisions based on specified criteria.

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

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
54
Q

Describe the syntax of an IF statement:

A

if (condition) { return}

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

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
56
Q

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

A

Logical And (&&) or Logical OR (||)

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

What is the purpose of a loop?

A

A loop is a programming structure that repeats a sequence of instruction until a specific condition is met.

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

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

A

to check if the code needs to keep iterating

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

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

A

repetition of the for loop code block

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

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

A

before each iteration of the loop

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

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

A

BEFORE ANYTHING , ONLY HAPPENS ONE TIME, it happens in the beginning

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

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

A

after initialization, before each iteration the condition is checked to allow the loop to get running until condition is met.

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

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

A

at the end of each iteration and before the condition is checked again.

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

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
65
Q

What does the ++ increment operator do?

A

Adds one (value of variable goes up by 1 and assigns that to new variable)

ex. var i = 0

i++

i now equals 1.

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

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
67
Q

Why do we log things to the console?

A

We use it to debug our code and log our progress

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

What is a ‘model’?

A

Example of a structure, representation of an object

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

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

A

HTML

70
Q

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

A

JavaScript

71
Q

What is a DOM Tree?

A

DOM tree is the model of the DOM, its a tree of elements with all of its children elements.

72
Q

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

A

document.getElementByID(‘id’) & document.querySelector(‘css selector’)

73
Q

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

A

document. getElementsByClassName(‘class’)
document. getElementsByTagName(‘tag’)
document. querySelectorAll(‘css selector’)

74
Q

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

A
  • It saves time for the browser looking through the DOM Tree to find the same element again
  • It stores the variable as a reference
75
Q

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

A

console.dir(‘ ‘);

76
Q

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

A

It allows all the html in the body to load first before the javascript loads, it can prevent errors and speed up website response time.

77
Q

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

A

‘Css’ selector’ and returns a single element node

78
Q

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

A

‘Css selector’ and returns one or more elements as a NodeList.

79
Q

What is the purpose of events and event handling?

A
  • Event listeners wait for a specific event to occur and does a responsive function in response to it
  • Handling is creating code to create events (functions, has event parameter)
80
Q

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

A

NO

81
Q

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

A

.addEventListener()

82
Q

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.

83
Q

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

A

Event

84
Q

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

A
  • It tells you were the event occurred on the page

- MDN

85
Q

What is the difference between these two snippets of code?

A
  • The second one has a callback function

- The second one has the handle click being called

86
Q

What is the claaName property of element objects?

A

it gets and sets the value of a class attribute

87
Q

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

A

querySelector() first and assign to variable

use the class name property to modify

88
Q

How do you update text within an element using JavaScript?

A

update the text within the element

89
Q

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

A

NO

90
Q

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

A

much more efficient and easier

91
Q

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

A

blur

92
Q

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

A

input

93
Q

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

A

submit

94
Q

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

A

focus

95
Q

What does the event.preventDefault() method do?

A

prevents the browser from reloading the page

96
Q

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

A

reload the page

97
Q

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

A

elements property

98
Q

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

A

value property

99
Q

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

A

easy to get lost and difficult to retrace your steps, makes debugging harder

100
Q

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

A

check your progress, check for errors

101
Q

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

A

No, you must use appendChild() method to add elements into a page

102
Q

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

A

appendChild() method

103
Q

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

A

(‘name’, ‘value)

104
Q

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

A
  1. createElement

2. appendChild

105
Q

What is the textContent property of an element object do?

A

checks the text of an element or sets new text for it

106
Q

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

A

setAttribute

className

107
Q

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

A

Reusability, can use the function elsewhere in your code

gives a name to a process

108
Q

What is event.target?

A

Finds where the event was dispatched from

109
Q

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

A

Event bubbling (the event starts at the most specific node and flows OUTWARD to the least specific one).

110
Q

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

A

-event.target.tagName()

tagName is always all CAPS

111
Q

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

A

Takes a css selector as the argument, returns the event.target of the parent element where the event occured

112
Q

How can you remove an element from the DOM?

A

remove()

closestElement.remove()

113
Q

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

assign the event to the parent of the element

114
Q

What is the event.target?

A

DOM element where the event occured

115
Q

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

A

it makes the element invisible and removes it from the document flow

116
Q

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

A

takes a css.selector as an argument as a ‘string’ and it returns the element of which you called the element on

117
Q

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

A

getAttribute method

118
Q

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

A

every step

119
Q

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

you would have to add an eventListener to every single element

120
Q

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

you would have to check each element individually instead

121
Q

What is JSON?

A

JavaScript Object Syntax, text-based format for representing structured data based on JavaScript Object Syntax. Used for transmitting data in Web Applications. Exists as a string - Useful when you want to transmit data across a network.

122
Q

What is 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 send it over the network.
  • Deserialization is the reverse process: turning a stream of bytes into an object in memory.
123
Q

Why are serialization and deserialization useful?

A

Serialization can convert these complex objects into byte strings for such use. After the byte strings are transmitted, the receiver will have to recover the original object from the byte string

124
Q

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

A
  • JSON.Stringify

- Takes a JavaScript Object and then transforms it into a JSON string

125
Q

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

A
  • JSON.parse

- Takes a JSON string and then transforms it into a JavaScript Object

126
Q

How do you store data in LOCAL STORAGE?

A

SetItem()

127
Q

How do you retrieve data from local storage?

A

getItem()

128
Q

What data type can local storage save in the browser?

A

strings

129
Q

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

A

Before the page unloads(close tab or refresh)

130
Q

What is a method?

A

function that is a property of an object.

131
Q

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

A
  1. call –> object.call()–> has paranthesis.

2. definition –> funcction defintion + code block

132
Q

Describe method definition syntax (structure).

A

have a property name: function keyword (parameters) {
code block}
object.property –>and then assign funcction

133
Q

Describe method call syntax (structure).

A

object name.methodname();

134
Q

How is a method different from any other function?

A

we need dot or bracket notation to show where that method is coming from.
its insidde an object

135
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects can container datas and behavior under the object

136
Q

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

A
  1. abstraction
  2. encapsulation
  3. inheritance
  4. polymorphism
137
Q

What is “abstraction”?

A

Making complex things into simply ways.

138
Q

What does API stand for?

A

Application programming interface

139
Q

What is the purpose of an API?

A

allows users to use the interface independently of the implementation (abstraction).
Allows users to work with the system in a simple way fashion

140
Q

What is this in JavaScript?

A

Implicit parameter of every js function

141
Q

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

A

It is available in a function’s code black even though it was never included in the function’s parameter list or declared with var

142
Q

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

A

Call Time

143
Q

What does this refer to in the following code snippet?

A

There is not definition because we are not in call yet, only in definition time referring to character object.

144
Q

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

A

The result will be the string value Its me mario. we are calling from character.

145
Q

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

A

“Its a me, undefined’

window doesn’t have an object

146
Q

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

A

Nothing - can’t tell what the value is

147
Q

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

A

Object left to the dot. If there is no dot, then it’s the window.

148
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based Inheritance

149
Q

What is a prototype in JavaScript?

A

​​Prototypes are the mechanism by which JavaScript objects inherit features from one another

150
Q

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-based Inheritance

151
Q

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

A

Prototype

152
Q

What does the new operator do?

A

It creates an instance of a user-defined object type or of one of the built-in objects types that has a constructor function.

Creates blank javascript object

Adds a property to the new object (__proto__) that links to the constructor function’s prototype object

Give this variable a value

Return this if the function doesn’t retur

153
Q

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

A

.prototype

154
Q

What does the instanceof operator do?

A

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.

155
Q

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.

156
Q

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

clearInterval()

157
Q

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

A

setInterval()

158
Q

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

A

0

159
Q

What do setTimeout() and setInterval() return?

A

The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.

160
Q

What is a client?

A

Service requesters

161
Q

What is a server?

A

provider of the service

162
Q

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

A

GET

163
Q

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

A

HTTP method; a verb or noun that describes action being performed
The target request: either a URL or absolute path of the protocol, port, and domain are usually characterized by the request context.
HTTP version that is being used

164
Q

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

A

Protocol version: http version

Status code: example 404

Status text: text description of the status code to help humans understand http message

165
Q

What are HTTP headers?

A

What are HTTP headers?

Providing more information about what we are doing. What content type, length of the content.

166
Q

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

A

MDN

167
Q

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

A

No, They are not required!

168
Q

What is AJAX?

A

Ajax, which initially stood for Asynchronous JavaScript And XML, is a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.

169
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

170
Q

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

A

XMLHttpRequests()

171
Q

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

A

load

172
Q

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

A

The both share prototypes