Javascript Flashcards

1
Q

What is the purpose of variables?

A

To store data to use a later time

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

How do you declare a variable?

A

Use the keyword Var

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

=

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, Underscores and $

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

Variables are specific to how they are typed

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

To store and manipulate text

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

To store a value

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

To determine if something is false or true

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

Assigning a value to a variable

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

Change the 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 is an empty value and Undefined means that variable has been declared but not defined

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

Point of reference

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 Numbers Null Undefined Boolean

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

Number

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

What is string concatenation?

A

Combination of 2 or more string values

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

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

A

To add values or concatenate strings

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

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

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

A

Adds the value of the right operand to the variable and the assigns the result to the variable

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

What are objects used for?

A

To group variables or functions

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

What are object properties?

A

Variables stored in an obeject

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

Describe object literal notation.

A

{properties: value}

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 the two ways to get or update the value of a property?

A

Dot notation 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

To be put in a list

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

Describe array literal notation.

A

[values, values, values]

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 are numeric and will repair themselves if something is deleted

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

Array.length

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

Array.length - 1

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

What is a function in JavaScript?

A

Series of statements that is repeatable

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

Describe the parts of a function definition.

A

Function keyword name of function (parameter list) code block return statement function

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

Describe the parts of a function call.

A

Name of the function and arguments if it requires it

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

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

A

call has arguments and passes a value and definition has code block with steps

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

What is the difference between a parameter and an argument?

A

Parameters are the names listed in the function’s definition Arguments are the real values passed to the function

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

Why are function parameters useful?

A

its a tool that is generalized

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

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

A

Return statement ends the execution of a function, and returns control to the calling function

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

Why do we log things to the console?

A

To debug

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

What is a method?

A

Function being stored in a property

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

How is a method different from any other function?

A

Methods have to say where they’re coming from

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

How do you remove the last element from an array?

A

object.pop()

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

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

A

object.floor()

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

How do you generate a random number?

A
object.random()
function getRandomNumberInRange(start,end)
{
var randomNumber = math.floor(math.random()*(end-start) + 1) + start
return randomNumber
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

How do you delete an element from an array?

A

object.splice()

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

How do you append an element to an array?

A

object.push() or use object.unshift() to prepend

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

How do you break a string up into an array?

A

object.split()

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 because strings are immutable. Use console log to debug

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

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

A

Alot

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 the MDN Web docs?

A

30

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

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

A

Alot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
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
51
Q

Give 6 examples of comparison operators.

A

, <=, >=, ===, !==

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

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

What is the purpose of an if statement?

A

Making decisions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
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
55
Q

Describe the syntax (structure) of an if statement.

A

if (condition) {}

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

What are the three logical operators?

A

&&, ||, !

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

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

A

&& and ||

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

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

What is the purpose of a loop?

A

To allow us to repeat code

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

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

A

In the beginning

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

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

A

The condition is checked before each iteration

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

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

A

Is before anything

63
Q

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

A

Is evaluated once before every iteration

64
Q

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

A

After each iteration

65
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

66
Q

What does the ++ increment operator do?

A

Increments the value by 1

67
Q

How do you iterate through the keys of an object?

A

For in

68
Q

Why do we log things to the console?

A

To debug

69
Q

What is a “model”?

A

Representation of the original

70
Q

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

A

The HTML doc

71
Q

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

A

Javascript Objects

72
Q

What is a DOM Tree?

A

Represents the page so that programs can change the document structure, style, and content

73
Q

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

A

.getElementByID()

.queryselector()

74
Q

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

A

.queryselectorall()

75
Q

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

A

To be able to access it better

76
Q

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

A

console.dir

77
Q

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

A

So all the contents can load first

78
Q

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

A

Returns the first Element within the document that matches the specified selector, or group of selectors

79
Q

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

A

Takes in node list and return everything

80
Q

Why do we log things to the console?

A

To debug

81
Q

What is the purpose of events and event handling?

A

To verify user inputs

82
Q

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

A

No

83
Q

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

What is a callback function?

A

A function being passed as a value

85
Q

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

A

Information about the event that has occurred

86
Q

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

A

It is a reference to the object to where the event occurred. More information could be found on MDN

87
Q

What is the difference between these two snippets of code?

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

A

First one has a variable

Second one has a function being called

88
Q

What is the className property of element objects?

A

Used to update the class attribute and get the class

89
Q

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

A

Query select the the class and use the .classname to update the attribute

90
Q

What is the textContent property of element objects?

A

Allow is to up date text

91
Q

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

A

.textcontent property on element using the DOM

92
Q

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

A

No

93
Q

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

94
Q

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

A

We don’t want to look elsewhere for the information

95
Q

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

A

Focus

96
Q

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

A

Blur

97
Q

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

A

Input

98
Q

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

A

Submit

99
Q

What does the event.preventDefault() method do?

A

Prevents default action

100
Q

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

A

Deletes the data

101
Q

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

A

Elements property

102
Q

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

A

Value property

103
Q

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

A

The code can potentially be broken and will be more difficult to find out where the code went wrong

104
Q

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

A

You’ll be able to see an errors as they occur when writing your code

105
Q

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

A

No

106
Q

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

A

append.child()

107
Q

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

A

‘name of attribute’, ‘value of the attribute’

108
Q

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

A

create function
assign var to document.createElement(‘name of element’) method and appendChild to that var and return it from the function and call it

109
Q

What is the textContent property of an element object for?

A

Contains the text within the element

110
Q

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

A

setAttribute, className

111
Q

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

A

We dont have to physically write in anything to the document reuse the function on a different section

112
Q

What is the event.target?

A

Stores event where it originated from

113
Q

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

A

Event bubbling

114
Q

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

A

.tagName

115
Q

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

A

Selector returns the dom tree

116
Q

How can you remove an element from the DOM?

A

object.remove()

117
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

Add event listener to that parent

118
Q

What is the event.target?

A

A reference to the object onto which the event was dispatched

119
Q

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

A

Removed from the document flow

120
Q

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

A

Selector string and returns a boolean (if element matches css selector)

121
Q

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

A

getAttribute

122
Q

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

A

All the time

123
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

Add event listener for the new tab node

124
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

Write code for every situation

125
Q

What is a method?

A

A function stored in a property of an object

126
Q

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

A

Definition: “property:function() include code block”

Call :”property.method()”

127
Q

Describe method definition syntax (structure).

A

Definition: “property:function()”

128
Q

Describe method call syntax (structure).

A

Call: “property.method()”

129
Q

How is a method different from any other function?

A

Method are functions attached to objects

130
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects can contain data and behavior

131
Q

What is “abstraction”?

A

Taking something complex and simplifying it

132
Q

What does API stand for?

A

Application programming interface

133
Q

What is the purpose of an API?

A

Delivers a user response to a system and sends the system’s response back to a user.

134
Q

What is the purpose of an API?

A

Delivers a user response to a system and sends the system’s response back to a user.

135
Q

What is “this” in JavaScript?

A

Where the object code is run

136
Q

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

A

It is include in the function scope even though its not defined

137
Q

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

A

Call time

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

Nothing

139
Q

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

A

Its me mario because calling this property

140
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

Its me undefined because the object doesn’t exist

141
Q

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

A

You cant

142
Q

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

A

The object of the method is being invoked on it. this is only a value when the method is being invoked it is the left of the dot

143
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype based inheritance

144
Q

What is a prototype in JavaScript?

A

JavaScript objects inherit features from one another

145
Q

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

Prototypal inheritance

146
Q

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

A

proto

147
Q

What does the new operator do?

A

Creates a blank, plain JavaScript object.

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

Binds the newly created object instance as the “this” context

Returns “this” if the function doesn’t return an object.

148
Q

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

A

Prototype property

149
Q

What does the instanceof operator do?

A

Returns true or false if object on the left matches the right

150
Q

What is a “callback” function?

A

A function passed into another function as an argument

151
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

setTimeout

152
Q

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

A

setInterval

153
Q

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

A

0 default time

154
Q

What do setTimeout() and setInterval() return?

A

intervalID