JavaScript (Junior Side) Flashcards

(169 cards)

1
Q

What is the purpose of variables?

A

they are a way to store information so that we can come back to it later.

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

What is the purpose of a boolean?

A

To make logical decisions.

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

How do youdeclarea variable?

A

by using var, const, or let

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

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

A

By using the assignment operator ( = )

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

What characters are allowed in variable names?

A

letter, number, or dollar sign $

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

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

A

capitalized and lowercase letters, even if they are the same letter, will have two different values if assigned to a variable

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

What is the purpose of a string?

A

For storing a sequence of characters that javScript will not try to interpret / creating “text”

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

What is the purpose of a number?

A

For numbers that may / will be used in mathematical operations

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

How do you update the value of a variable?

A

put the name of the variable with an assignment operator and a new value.

Do not use the “var, let, or const” keywords, because the variable has already been declared.

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

What does the=operator mean in JavaScript?

A

assigns the value of its right operand to its left operand.

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

What is the difference betweennullandundefined?

A

Null is an intentional assignment of no value.

Undefined is an empty value that JS is ‘free to use’

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

For clarity when coming back to reference code at a later time.

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

Number

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

What is string concatenation?

A

adding strings together to make a new string

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

Does concat change the original string?

A

No, it makes new strings that consist of the previous strings

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

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

A

math or concatenation

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

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

A

makes a lasting change / adds and assigns

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

What are objects used for?

A

a way to group together sets of data that are related to each other

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

What are object properties?

A

variables inside of an object

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

Describe object literal notation.

A

curly brace, then a property, the a colon, then a comma, then the next property declaration, etc., ended by a closing curly brace

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

How do you remove a property from an object?

A

use the delete operator

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

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
25
what are arrays used for?
for storing a sequence of related information for use at a later time
26
describe array literal notation
[ 'word', 'word2' ]
27
how are arrays different from "plain" objects?
arrays are indexed/ have an order, objects are not
28
what number represents the first index of an array?
0
29
what is the length property of an array?
arrayName.length, a true count of items that are indexed in the array
30
how do we calculate last index of an array?
array.length -1
31
What is a function in JavaScript?
Functions allow you to package up code for use later in your program.
32
Describe the parts of a function definition.
function keyword optional name parameters (separated , by , commas) start of the code block ( { ) with a return...maybe optional return statement close of the code block (})
33
Describe the parts of a function call.
function name ( ) parenthesis arguments list
34
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call just has the name and arguments function definition has name, parameters, { } , and code block
35
What is the difference between a parameter and an argument?
when we define a function, we declare parameters and that when we call a function, we pass it arguments parameter is placeholder, argument is the actual value
36
Why are function parameters useful?
They give us more control over the function
37
What two effects does a return statement have on the behavior of a function?
1. Causes the function to produce a value we can use in our program. 2. Prevents any more code in the function's code block from being run.
38
What is a method?
A method is a function which is a property of an object.
39
why do we log things to the console?
its a debugging tool
40
What is a method?
a function stored in the property of an object
41
How is a method different from any other function?
Methods must be attached to an object, functions do not
42
How do you remove the last element from an array?
.pop( ) method
43
How do you round a number down to the nearest integer?
Math.floor( ) method | floor method of the math object
44
How do you generate a random number?
Math.random( ) random method of the math object 0 0.999
45
How do you delete an element from an array?
.splice( ) method
46
How do you append an element to an array?
.push ( ) method
47
How do you break a string up into an array?
.split ( ) method
48
Do string methods change the original string? How would you check if you weren't sure?
No! console.log( ) the string using a method
49
Roughly how many string methods are there according to the MDN Web docs?
A LOT
50
Is the return value of a function or method useful in every situation?
No, example . push( ) or .pop( )
51
Roughly how many array methods are there according to the MDN Web docs?
A LOT
52
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
53
Give 6 examples of comparison operators.
===, !==, < , > ,<= , >=
54
What data type do comparison expressions evaluate to?
booleans
55
What is the purpose of an if statement?
to make logical decisions in code
56
Is else required in order to use an if statement?
No
57
Describe the syntax (structure) of an if statement.
if keyword, condition, code block
58
What are the three logical operators?
&& , ||, ! and, or, not
59
How do you compare two different expressions in the same condition?
With a logical operator (either && or ||)
60
what is the purpose of a loop?
to repeat functionality when needed
61
What is the purpose of a condition expression in a loop?
to determine whether or not the loop continues repeating. if true, loop continues, if false, loop stops.
62
What does "iteration" mean in the context of loops?
one full time that the code block has been run.
63
When does the condition expression of a while loop get evaluated?
before the loop code block executes
64
When does the initialization expression of a for loop get evaluated?
once before anything happens
65
When does the condition expression of a for loop get evaluated?
before code block of next iteration, and after the final expression
66
When does the final expression of a for loop get evaluated?
before the condition, and after the code block runs
67
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
68
What does the ++ increment operator do?
adds one to the initialization expression
69
How do you iterate through the keys of an object?
with a for...in loop
70
Why do we log things to the console?
For debugging purposes
71
What is a "model"?
A visual representation of something
72
Which "document" is being referred to in the phrase Document Object Model?
the HTML document / the web page itsself
73
What is the word "object" referring to in the phrase Document Object Model?
the objects / nodes of the document
74
What is a DOM Tree?
the model of a webpage
75
Give two examples of document methods that retrieve a single element from the DOM.
querySelector(), getElementById()
76
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll(), getElementsByClassName()
77
Why might you want to assign the return value of a DOM query to a variable?
so we don't have to query the DOM again
78
What console method allows you to inspect the properties of a DOM element object?
console.dir( ) dir method of the console object
79
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
document needs to be read before JS can interact with it.
80
What does document.querySelector() take as its argument and what does it return?
Takes the element name, returns the first element that matches
81
What does document.querySelectorAll() take as its argument and what does it return?
Takes an element name, returns a static (not live) NodeList representing a list of the document's elements that match the specified group of selectors.
82
Why do we log things to the console?
for debugging purposes / so we know whats going on
83
What is the purpose of events and event handling?
they allow us to run code when the user interatcs with the page
84
Are all possible parameters required to use a JavaScript method or function?
No
85
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener()
86
What is a callback function?
a function that is passed as an argument to another function, to be called on at a later time during an event.
87
What object is passed into an event listener callback when the event fires?
event object
88
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick())
the top function will be called by the addEventListener method the bottom function is being called manually in the method, which will not work
89
What is the className property of element objects?
it is a property that gets and sets the value of the class attribute of the specified element.
90
What is the event.target?
the element that dispatches the element. the point of interaction on the DOM.
91
How do you update the CSS class attribute of an element using JavaScript?
use the className property
92
What is the textContent property of element objects?
a property that is used to grab the text content from an element
93
How do you update the text within an element using JavaScript?
by using the textContent property
94
Is the event parameter of an event listener callback always useful?
No
95
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
96
Why is storing information about a program in variables better than only storing it in the DOM?
Because they can be accessed at a later time / makes work easier
97
What event is fired when a user places their cursor in a form control?
Focus
98
What event is fired when a user's cursor leaves a form control?
Blur
99
What event is fired as a user changes the value of a form control?
Input
100
What event is fired when a user clicks the "submit" button within a form ?
Submit
101
What does the event.preventDefault() method do?
tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.
102
What does submitting a form without event.preventDefault() do?
It can cause unwanted submissions of forms / actions to occur
103
What property of a form element object contains all of the form's controls?
The elements() property of the form object
104
What property of a form control object gets and sets its value?
The elements property
105
What is one risk of writing a lot of code without checking to see if it works so far?
You will not catch any errors and waste time
106
What is an advantage of having your console open when writing a JavaScript program?
You can see errors as they appear
107
Does the document.createElement() method insert a new element into the page?
It creates a new element on the DOM tree
108
How do you add an element as a child to another element?
appendChild(pass in Dom element)
109
What do you pass as the arguments to the element.setAttribute() method?
attribute name, and values
110
What steps do you need to take in order to insert a new element into the page?
document.CreatElement() add child elements to that put the element to the DOM tree by appending it to a parent element using (appendChild) on the parent object
111
What is the textContent property of an element object for?
to create or change text content
112
Name two ways to set the class attribute of a DOM element.
className() | setAttribute()
113
What are two advantages of defining a function to create something (like the work of creating a DOM tree)?
1. You can repeat functionality quickly. | 2. You save time.
114
What is the event.target?
the target of the event
115
Why is it possible to listen for events on one element that actually happens to its descendent elements?
because of event delegation / the bubble effect
116
What DOM element property tells you what type of element it is?
the tagName property
117
What does the element.closest() method take as its argument and what does it return?
Takes a CSS selector as its argument, and returns the closest ancestor Element or itself, which matches the selectors. If there are no such element, null.
118
How can you remove an element from the DOM?
using the remove() method
119
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 the eventListener to the parent element
120
What is the affect of setting an element to display: none?
the element and its children disappear from the page
121
What does the element.matches() method take as an argument and what does it return?
takes a selector and returns a boolean value
122
How can you retrieve the value of an element's attribute?
getAttribute()
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?
you would need to add multiple listener events
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?
multiple conditionals would need to be used
125
What does JSON stand for?
Java Script Object Notation
126
What are serialization and deserialization?
Serializtion converts an object into a byte string, deserialization is when that data gets parsed
127
Why are serialization and deserialization useful?
it allows transfer of information across networks
128
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
129
How do you deserialize a JSON string into a data structure using JavaScript?
parse()
130
How do you store data in localStorage?
setItem()
131
How do you retrieve data from localStorage?
getItem()
132
What data type can localStorage save in the browser?
JSON Strings
133
When does the 'beforeunload' event fire on the window object?
The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point.
134
What is a method?
a function which is a property of an object
135
How can you tell the difference between a method definition and a method call?
the same way you tell the difference between a function definition and a function call
136
Describe method definition syntax (structure).
it is the same as a function definition: function name (){ return }
137
Describe method call syntax (structure).
just like a function call
138
How is a method different from any other function?
it must be stored within the property of an object
139
What is the defining characteristic of Object-Oriented Programming?
140
What are the four "principles" of Object-Oriented Programming?
Abstraction Encapsulation Inheritance Polymorphism
141
What is "abstraction"?
being able to work with (possibly) complex things in simple ways
142
What does API stand for?
application programming interface
143
What is the purpose of an API?
a way for computers to communicate with each other, and for users to interact with simply
144
What is this in JavaScript?
an implicit parameter of all JavaScript functions.
145
What does it mean to say that this is an "implicit parameter"?
a parameter that is available in a function's code block even though it was never included in the function's parameter list or declared with var.
146
When is the value of this determined in a function; call time or definition time?
at call time
147
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); } }; ```
the character object
148
How can you tell what the value of this will be for a particular function or method definition?
you dont know
149
How can you tell what the value of this is for a particular function or method call?
look to the left of the dot
150
What kind of inheritance does the JavaScript programming language use?
prototype-based
151
What is a prototype in JavaScript?
an object that contains properties and (predominantly) methods that can be used by other objects.
152
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?
because of the prototype object
153
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
within the prototype chain
154
What does the new operator do?
it instantiates a new javascript object
155
What property of JavaScript functions can store shared behavior for instances created with new?
the prototype property
156
What does the instanceof operator do?
tests whether or not the thing being evaluated was created by the "creator" that we are looking at. "was ____ created from ____?"
157
what is a client?
the person making the request
158
what is a server?
a provider of services
159
Which HTTP method does a browser issue to a web server when you visit a URL?
GET request
160
What three things are on the start-line of an HTTP request message?
http method, request target, request version
161
What three things are on the start-line of an HTTP response message?
protocol version, status code, status text
162
What are HTTP headers?
they let let the client and the server pass additional information with an HTTP request or response.
163
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
164
Is a body required for a valid HTTP request or response message?
No
165
What is AJAX?
a technique for loading data into part of a page without having to refresh the entire page. The data is often sent in a format called JavaScript Object Notation (or JSON).
166
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
167
Which object is built into the browser for making HTTP requests in JavaScript?
The XMLHttpRequest object
168
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
the load event
169
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
because of prototypical inheritance