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
Describe array literal notation.
[values, values, values]
26
How are arrays different from "plain" objects?
Arrays are numeric and will repair themselves if something is deleted
27
What number represents the first index of an array?
0
28
What is the length property of an array?
Array.length
29
How do you calculate the last index of an array?
Array.length - 1
30
What is a function in JavaScript?
Series of statements that is repeatable
31
Describe the parts of a function definition.
Function keyword name of function (parameter list) code block return statement function
32
Describe the parts of a function call.
Name of the function and arguments if it requires it
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
call has arguments and passes a value and definition has code block with steps
34
What is the difference between a parameter and an argument?
Parameters are the names listed in the function's definition Arguments are the real values passed to the function
35
Why are function parameters useful?
its a tool that is generalized
36
What two effects does a return statement have on the behavior of a function?
Return statement ends the execution of a function, and returns control to the calling function
37
Why do we log things to the console?
To debug
38
What is a method?
Function being stored in a property
39
How is a method different from any other function?
Methods have to say where they're coming from
40
How do you remove the last element from an array?
object.pop()
41
How do you round a number down to the nearest integer?
object.floor()
42
How do you generate a random number?
``` object.random() function getRandomNumberInRange(start,end) { var randomNumber = math.floor(math.random()*(end-start) + 1) + start return randomNumber } ```
43
How do you delete an element from an array?
object.splice()
44
How do you append an element to an array?
object.push() or use object.unshift() to prepend
45
How do you break a string up into an array?
object.split()
46
Do string methods change the original string? How would you check if you weren't sure?
No because strings are immutable. Use console log to debug
47
Roughly how many string methods are there according to the MDN Web docs?
Alot
48
Roughly how many array methods are there according to the MDN Web docs?
30
49
Roughly how many array methods are there according to the MDN Web docs?
Alot
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
51
Give 6 examples of comparison operators.
, <=, >=, ===, !==
52
What data type do comparison expressions evaluate to?
Boolean
53
What is the purpose of an if statement?
Making decisions
54
Is else required in order to use an if statement?
No
55
Describe the syntax (structure) of an if statement.
if (condition) {}
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
&& and ||
58
What is the purpose of a condition expression in a loop?
To tell the loop when to stop
59
What is the purpose of a loop?
To allow us to repeat code
60
What does "iteration" mean in the context of loops?
In the beginning
61
When does the condition expression of a while loop get evaluated?
The condition is checked before each iteration
62
When does the initialization expression of a for loop get evaluated?
Is before anything
63
When does the condition expression of a for loop get evaluated?
Is evaluated once before every iteration
64
When does the final expression of a for loop get evaluated?
After each iteration
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break
66
What does the ++ increment operator do?
Increments the value by 1
67
How do you iterate through the keys of an object?
For in
68
Why do we log things to the console?
To debug
69
What is a "model"?
Representation of the original
70
Which "document" is being referred to in the phrase Document Object Model?
The HTML doc
71
What is the word "object" referring to in the phrase Document Object Model?
Javascript Objects
72
What is a DOM Tree?
Represents the page so that programs can change the document structure, style, and content
73
Give two examples of document methods that retrieve a single element from the DOM.
.getElementByID() | .queryselector()
74
Give one example of a document method that retrieves multiple elements from the DOM at once.
.queryselectorall()
75
Why might you want to assign the return value of a DOM query to a variable?
To be able to access it better
76
What console method allows you to inspect the properties of a DOM element object?
console.dir
77
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
So all the contents can load first
78
What does document.querySelector() take as its argument and what does it return?
Returns the first Element within the document that matches the specified selector, or group of selectors
79
What does document.querySelectorAll() take as its argument and what does it return?
Takes in node list and return everything
80
Why do we log things to the console?
To debug
81
What is the purpose of events and event handling?
To verify user inputs
82
Are all possible parameters required to use a JavaScript method or function?
No
83
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addeventlistener
84
What is a callback function?
A function being passed as a value
85
What object is passed into an event listener callback when the event fires?
Information about the event that has occurred
86
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
It is a reference to the object to where the event occurred. More information could be found on MDN
87
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick())
First one has a variable | Second one has a function being called
88
What is the className property of element objects?
Used to update the class attribute and get the class
89
How do you update the CSS class attribute of an element using JavaScript?
Query select the the class and use the .classname to update the attribute
90
What is the textContent property of element objects?
Allow is to up date text
91
How do you update the text within an element using JavaScript?
.textcontent property on element using the DOM
92
Is the event parameter of an event listener callback always useful?
No
93
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
More complicated
94
Why is storing information about a program in variables better than only storing it in the DOM?
We don't want to look elsewhere for the information
95
What event is fired when a user places their cursor in a form control?
Focus
96
What event is fired when a user's cursor leaves a form control?
Blur
97
What event is fired as a user changes the value of a form control?
Input
98
What event is fired when a user clicks the "submit" button within a ?
Submit
99
What does the event.preventDefault() method do?
Prevents default action
100
What does submitting a form without event.preventDefault() do?
Deletes the data
101
What property of a form element object contains all of the form's controls.
Elements property
102
What property of form a control object gets and sets its value?
Value property
103
What is one risk of writing a lot of code without checking to see if it works so far?
The code can potentially be broken and will be more difficult to find out where the code went wrong
104
What is an advantage of having your console open when writing a JavaScript program?
You'll be able to see an errors as they occur when writing your code
105
Does the document.createElement() method insert a new element into the page?
No
106
How do you add an element as a child to another element?
append.child()
107
What do you pass as the arguments to the element.setAttribute() method?
'name of attribute', 'value of the attribute'
108
What steps do you need to take in order to insert a new element into the page?
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
What is the textContent property of an element object for?
Contains the text within the element
110
Name two ways to set the class attribute of a DOM element.
setAttribute, className
111
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
We dont have to physically write in anything to the document reuse the function on a different section
112
What is the event.target?
Stores event where it originated from
113
Why is it possible to listen for events on one element that actually happen its descendent elements?
Event bubbling
114
What DOM element property tells you what type of element it is?
.tagName
115
What does the element.closest() method take as its argument and what does it return?
Selector returns the dom tree
116
How can you remove an element from the DOM?
object.remove()
117
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?
Add event listener to that parent
118
What is the event.target?
A reference to the object onto which the event was dispatched
119
What is the affect of setting an element to display: none?
Removed from the document flow
120
What does the element.matches() method take as an argument and what does it return?
Selector string and returns a boolean (if element matches css selector)
121
How can you retrieve the value of an element's attribute?
getAttribute
122
At what steps of the solution would it be helpful to log things to the console?
All the time
123
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?
Add event listener for the new tab node
124
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?
Write code for every situation
125
What is a method?
A function stored in a property of an object
126
How can you tell the difference between a method definition and a method call?
Definition: "property:function() include code block" | Call :"property.method()"
127
Describe method definition syntax (structure).
Definition: "property:function()"
128
Describe method call syntax (structure).
Call: "property.method()"
129
How is a method different from any other function?
Method are functions attached to objects
130
What is the defining characteristic of Object-Oriented Programming?
Objects can contain data and behavior
131
What is "abstraction"?
Taking something complex and simplifying it
132
What does API stand for?
Application programming interface
133
What is the purpose of an API?
Delivers a user response to a system and sends the system's response back to a user.
134
What is the purpose of an API?
Delivers a user response to a system and sends the system's response back to a user.
135
What is "this" in JavaScript?
Where the object code is run
136
What does it mean to say that "this" is an "implicit parameter"?
It is include in the function scope even though its not defined
137
When is the value of "this" determined in a function; call time or definition time?
Call time
138
``` 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); } }; ```
Nothing
139
Given the above character object, what is the result of the following code snippet? Why? character.greet();
Its me mario because calling this property
140
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
Its me undefined because the object doesn't exist
141
How can you tell what the value of "this" will be for a particular function or method definition?
You cant
142
How can you tell what the value of "this" is for a particular function or method call?
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
What kind of inheritance does the JavaScript programming language use?
Prototype based inheritance
144
What is a prototype in JavaScript?
JavaScript objects inherit features from one another
145
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?
Prototypal inheritance
146
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
_proto_
147
What does the new operator do?
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
What property of JavaScript functions can store shared behavior for instances created with new?
Prototype property
149
What does the instanceof operator do?
Returns true or false if object on the left matches the right
150
What is a "callback" function?
A function passed into another function as an argument
151
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?
setTimeout
152
How can you set up a function to be called repeatedly without using a loop?
setInterval
153
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 default time
154
What do setTimeout() and setInterval() return?
intervalID