JavaScript Flashcards

1
Q

what is the purpose of variables?

A

store data for reuse

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

how do you declare a variable?

A

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

var x = ‘string’;

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

however must start with letter, $, or _.

must not use - or .

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

the slightest capitalization difference for the same word will count as different variables

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

what is the purpose of string?

A

used when working with any kind of 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

for tasks that involve counting or calculating sums

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

what is the purpose of boolean?

A

helpful when determining which part of a script should run/ acts as an on or off switch

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

assignment operator

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

use the variable name, the equals sign, and the new 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 represents a reference that points to a nonexistent or invalid object or address

undefined is a value assigned to variables that have just been declared, or to formal arguments for which there are 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

easier to keep track of console output for yourself and others

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

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

placing string together to form a single output of string

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

A

concatenation and addition

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 a variable and 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

objects group together a set of variables and functions to create a model of something you would recognize from the real world

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

what are object properties?

A

exclusive variables - another way to store data

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

describe object literal notation

A

assigning the object properties within { }

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 object.property

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

use dot or 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

when you are working with a list or a set of values that are related to each other

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
describe array literal notation
var colors = [ ] ;
26
how are arrays different from "plain" objects?
arrays use indexes to keep track of items
27
what number represents the first index of an array?
0
28
what is the length property of an array?
tells how many items are in the array
29
how do you calculate the last index of an array?
array.length - 1
30
what is a function in JavaScript?
set of statements that perform a task
31
describe the parts of a function definition
function keyword, optional name, parameters, code block, return statement, {}
32
describe the parts of a function call
function name, arguments ( )
33
when comparing them side-by-side, what are the differences between a function call and a function definition?
function call - actually using the function function definition - creating the code to run
34
what is the difference between a parameter and an argument?
parameters are variables that doesn't have a value yet arguments are the user values
35
why are function parameters useful?
used as placeholders for when the function is called
36
what two effects does a return statement have on the behavior of a function?
causes the function to produce a value we can use prevents any more code in the function's code block from being run
37
why do we log things to the console?
during development, check if output matches what you are expecting debugging
38
what is a method?
function which is a property of an object
39
how do you remove the last element from an array?
.pop()
40
how do you round a number down to the nearest integer?
Math.floor()
41
how do you generate a random number?
Math.random()
42
how do you delete an element from an array?
.splice()
43
how do you append an element to an array?
.push()
44
how do you break a string up into an array?
.split()
45
do string methods change the original string? How would you check if you weren't sure?
they return a new string check with MDN - documentation or try yourself on console log
46
roughly how many string methods are there according to the MDN web docs?
~35 remember to check MDN
47
is the return value of a function or method useful in every situation?
no, sometimes function/methods do not need to return a value
48
roughly how many array methods are there according to the MDN web docs?
~30 remember to check MDN
49
what three-letter acronym should you always include in your google search about a JavaScript method or CSS property?
MDN
50
give 6 examples of comparison operators
``` === !== >= <= > ```
51
what data type do comparison expressions evaluate to?
boolean
52
what is the purpose of an if statement?
checks if a condition is true or false to execute code
53
is else required in order to use an if statement?
no, can be used to just check condition
54
describe the syntax(structure) of an if statement
if conditional statement, ( condition ), { } if code block
55
what are the three logical operators
&& logical and || logical or ! logical not
56
how do you compare two different expressions in the same condition?
logical and, logical or
57
what is the purpose of a loop?
loops check a condition; if it returns true, a code block will run. condition checked again and will repeat if still true. repeats until condition returns false
58
what is the purpose of a condition expression in a loop?
have the loop continue to run until the counter reaches a specified number
59
what does "iteration" mean in the context of loops?
iteration refers to the process in which the content of loop is executed once
60
when does the condition expression of a while loop get evaluated?
evaluated before each code block
61
when does the initialization expression of a for loop get evaluated
evaluated before the loop begins
62
when does the condition expression of a for loop get evaluated
after initialization, before code block runs
63
when does the final expression of a for loop get evaluated?
evaluated at the end of each loop iteration. this occurs before the next evaluation of a condition
64
besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
65
what does the ++ increment operator do?
adds one
66
how do you iterate through the keys of an object?
for/in loop
67
what event is fired when a user places their cursor in a form control?
focus
68
what event is fired when a user's cursor leaves a form control?
blur
69
what event is fired as a user changes the value of a form control?
input
70
what event is fired when a user clicks the "submit" button within a form?
submit
71
what does the event.preventdefault() method do?
tells the user agent that if the vent does not get explicitly handled, its default action should not be taken as it normally would be
72
what does submitting a form without event.preventDefault() do?
reloads the page
73
what property of a form element object contains all of the form's controls
elements
74
what property of form a control object gets and sets its value
.value property
75
what is one risk of writing a lot of code without checking to see if it works so far?
there could be some typo or miscalculated result that messes with the whole code
76
what is an advantage of having your console open when writing a javascript program?
you can test things out and prevent possible bugs
77
what is the event.target?
reference to the object onto which the event fired
78
what is the effect of setting an element to display: none?
element will not be visible
79
what does the element.matches() method take as an arugment and what does it return?
selectorString as argument returns boolean
80
how can you retrieve the value of an element's attribute?
.getAttribute() method
81
at what steps of the solution would it be helpful to log things to the console?
whenever you are using a method, property, or calculation
82
if you were to add another tab and view to your HTML, but you didn't use event delegation, how would your JS code be writen instead?
need to add event listeners to each new node
83
if you didn't use a loop to conditionally show or hide the views in the page, how would your JS code be written instead?
you would have to get the variable for each index and compare for every single one
84
what is JSON?
text-based data format following JS object syntax
85
what are serialization and deserialization?
serialization - process of converting an Object into stream of bytes so that it can be transferred over a network or stored in a persistent storage deserialization - fetch a stream of bytes from network or persistence storage and convert it back to the Object with the same state
86
why are serialization and deserialization useful?
compress/decompress data to keep accurate data when sharing with others
87
how do you serialize a data structure into a JSON string using Javascript?
JSON.stringify() method
88
how do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse() method
89
how do you store data in localStorage?
.setItem() method
90
how do you retrieve data from localStorage?
.getItem() method
91
what data type can localStorage save in the browser?
string
92
when does the 'beforeunload' event fire on the window object?
fired when the window, the document, and its resources are about to be unloaded (when user leaves/navigates away from the page
93
what is a method?
function which is a property of an object
94
how can you tell the difference between a method definition and a method call?
method definition is where the method is built with code block method call is when the method definition is being used
95
describe method definition syntax (structure)
variable object declration followed by property name and function() with code block
96
describe method call syntax(structure)
method.function();
97
how is a method different from any other function?
a method is a function, which is a property of an object. use dot notation/bracket notation to access
98
what is the defining characteristic of object-oriented programming?
objects can contain both data (as properties) and behavior (as methods)
99
what are the four "principles" of object-oriented programming
abstraction encapsulation inheritance polymorphism
100
what is abstraction?
the process of removing physical, spacial, or temporal details or attributes in the study of objects or system to focus attention on details of greater importance; similiar in nature to the process of generalization ex; flicking the lights is more than just turning a switch. there are many micro events that occur, but all you need to know is that you need to flip the switch to turn on/off the lights
101
what does API stand for?
application programming interface
102
what is the purpose of an API?
it defines interactions between multiple software intermediaries. it defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conversations to follow, etc.
103
what is this in JS?
the object a property of an execution context(global, function, or eval) that, in non-strict mode is always a reference to an object and in strict mode can be any value
104
what does it mean to say that this is an "implicit parameter?"
it is available in a function's code block even though it was never included in the function's parameter list or declared with var
105
when is the value of this determined in a function; call time or definition time?
call time
106
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); } }; ```
we don't know yet as this is the definition time
107
given the above character object, what is the result of the following code snippet? why? character.greet();
It's a me, Mario! greet is a function that will return a message
108
given the character object, what is the result of the following code snippet? why? var hello = character.greet;
hello(); it's a me, undefined because this is being used on the window object which doesn't have a firstName property defined
109
how can you tell what the value of this will be for a particular function or method definition?
not in strict mode, this will default to the global object, which is a window in a browser in strict mode, if the value of this is not set when entering an execution context, it remains as undefined
110
how can you tell what the value of this is for a particular function or method call?
the value of this can be recognized as "the object to the left of the dot" when the function is called (as a method) if there is no value to the left of the dot when the function is called, then by default, this will be the global window object if you cannot see the function being called, then you do not know what the value of this will be
111
what kind of inheritance does the JS programming language use?
prototype-based inheritance a style of object-oriented programming in which behavior reuse (known as inheritance) is performed via a process of reusing existing objects that serve as prototypes
112
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?
prototype chain
113
if an object does not have it's own property or method by a given key, where does JS look for it?
prototype object, then to the object's
114
what does the new operator do?
lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function - creates a blank, plain JS object - links the newly created object to another object by setting the other object as its parent prototype - passes the newly created object from step 1 as this context - returns this if the function doesn't return an object
115
what property of JS functions can store shared behavior for instances created with new?
prototype property
116
what does the instanceof operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. return value is a boolean value
117
what is a callback function?
function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action
118
besides adding an event listener callback function to an element or the document, what is one way to delay the execution of JS function until some point in the future?
setTimeout() method
119
how can you set up a function to be called repeatedly without using a loop?
setInterval() method
120
what is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle
121
what do setTimeout() and setInterval() return?
setTimeout() return is a positive integer value which identifies the timer created by the call to setTimeout() setInterval() return is a numeric, non-zero value which identifies the timer created by the call to setInterval()
122
what is AJAX?
a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequeseet
123
what does the AJAX acronym stand for?
asynchronous Javascript and XML
124
what event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
125
an XMLHttpRequest object has an addEventListener() method just like DOM elements. how is it possible that they both share this functionality?
shares prototype
126
what is Array.prototype.filter useful for?
creates a new array with all elements that pass the test implemented by the provided function
127
what is Array.prototype.map useful for?
it creates a new array populated with results of calling a provided function on every element in the calling array
128
what is Array.prototype.reduce useful for?
when you want to reduce each element of an array to a single output value