JavaScript Flashcards

1
Q

JavaScript Primitives and Variables:
What is the purpose of variables?

A

to store data for the future action/reference

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

JavaScript Primitives and Variables:
How do you declare a variable?

A

variable keyword
variable name ;

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

JavaScript Primitives and Variables:
How do you initialize (assign a value to )a variable?

A

(variable keyword
variable name)
assignment operator (=)
variable value ;

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

JavaScript Primitives and Variables:
What characters are allowed in variable names?

A

letters, dollar sign, underscore (only first three can start the variable name) and numbers (no dashes or periods)

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

JavaScript Primitives and Variables:
What does it mean to say that variable names are “case sensitive”?

A

it means that there’s a difference between a word starting with lowercase and that same word starting with a capital letter.
(bad practice to have same name using difference cases)

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

JavaScript Primitives and Variables:
What is the purpose of a string?

A

Strings are used when working with text
(typically used to add new content to a page and can contain HTML markup)

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

JavaScript Primitives and Variables:
What is the purpose of a number?

A

Numbers are used in tasks that involve counting or calculating sums

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

JavaScript Primitives and Variables:
What is the purpose of a boolean?

A

Booleans are used to determine which parts of a script should run.
Used to make decisions

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

JavaScript Primitives and Variables:
What does the = operator mean in JavaScript?

A

The equal sign means that you are going to assign a value to a variable

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

JavaScript Primitives and Variables:
How do you update the value of a variable?

A

variable name
assignment operator
and then the new value ;

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

JavaScript Primitives and Variables:
What is the difference between null and undefined?

A

null intentional absence of a value
undefined creates a variable but assigns it no value

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

JavaScript Primitives and Variables:
Why is it a good habit to include “labels” when you log values to the browser console?

A

If you do not include “labels” it can be confusing

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

JavaScript Primitives and Variables:
Give five examples of JavaScript primitives

A

number, string, boolean, null, undefined

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

JavaScript Operators and Expressions:
What data type is returned by an arithmetic operation?

A

numbers

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

JavaScript Operators and Expressions:
What is string concatenation?

A

the process of joining together two or more strings to create one new string

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

JavaScript Operators and Expressions:
What purpose(s) does the + plus operator serve in JavaScript?

A

the plus operator adds numbers together or concatenates

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

JavaScript Operators and Expressions:
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

JavaScript Operators and Expressions:
What does the += “plus-equals” operator do?

A

it adds the value to the right of the 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

JavaScript Objects:
What are objects used for?

A

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

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

JavaScript Objects:
what are object properties?

A

variables that give information about an object

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

JavaScript Objects:
Describe object literal notation.

A

{
key: value ,
}

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

JavaScript Objects:
How do you remove a property from an object?

A

delete operator followed by objectName.propertyName
(period is member operator)

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

JavaScript Objects:
What are the two ways to get or update the value of a property?

A

dot notation or square bracket notation

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

JavaScript Arrays:
What are arrays used for?

A

for lists of data where either the order of the list is extremely important or unimportant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
JavaScript Arrays: Describe array literal notation
[item, item, etc]
26
JavaScript Arrays: How are arrays different from 'plain' objects?
all arrays have length property objects do not have an order (automatically updates as you add things. Arrays, you call a method to add items. Objects, you assign values directly to property)
27
JavaScript Arrays: What number represents the first index of an array?
[0]
28
JavaScript Arrays: What is the length property of an array?
property.length get the number of items in the array
29
JavaScript Arrays: How do you calculate the last index of an array?
subtract 1 from property.length
30
JavaScript Functions: What is a function in JavaScript?
chunk of code that performs a task that returns something (most the time)
31
JavaScript Functions: Describe the parts of a function definition
functionKeyword optionalFunctionName (parameters) {function code block optionalReturnStatement} end of function code block
32
JavaScript Functions: Describe the parts of a function call
functionName(arg1, arg2, etc);
33
JavaScript Functions: When comparing them side-by-side, what are the differences between a function call and a function definition?
a function definition has the functionKeyword and a code block, function call does not
34
JavaScript Functions: What is the difference between a parameter and an argument?
parameters are part of a function declaration and act as placeholders arguments are part of function call and take the place of parameters
35
JavaScript Functions: Why are function parameters useful?
they act as placeholders for arguments
36
JavaScript Functions: 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
37
JavaScript If: Give 6 examples of comparison operators
strictly equal to (===), strictly not equal to (!==), greater than, less than, greater than or equal to, less than or equal to, equal to (==)
38
JavaScript If What data type do comparison expressions evaluated to?
boolean
39
JavaScript If What is the purpose of an if statement?
to make decisions
40
JavaScript If: Is else required in order to use an if statement?
no
41
JavaScript If: Describe the syntax(structure) of an if statement?
if keyword, condition,
42
JavaScript If: What are the three logical operators?
logical and (&&), logical or (||), logical not (!)
43
JavaScript If: How do you compare two different expressions in the same condition?
logical and logical or
44
JavaScript Methods: Why do we log things to the console?
logging things into the console helps with debugging, so we can see where the browser prints errors and warnings in our code
45
JavaScript Methods: What is a method?
A method is a function which is a property of an object
46
JavaScript Methods: How is a method different from any other function?
methods are associated with objects
47
JavaScript Methods: How do you remove the last element from an array?
pop()
48
JavaScript Methods: How do you round a number down to the nearest integer?
Math.floor()
49
JavaScript Methods: How do you generate a random number?
Math.random()
50
JavaScript Methods: How do you delete an element from an array?
splice()
51
JavaScript Methods: How do you append an element to an array?
push()
52
JavaScript Methods: How do you break a string up into an array?
str.split()
53
JavaScript Methods: Do string methods change the original string? How would you check if you weren't sure?
doesn't change the string console.log to check
54
JavaScript Loops: What is the purpose of a loop?
Way to repeat a code block until the condition is no longer true.
55
JavaScript Loops: What is the purpose of a condition expression in a loop?
it creates a stopping point
56
JavaScript Loops: What does 'iteration' mean in the context of loops?
One completion of the loop code block
57
JavaScript Loops: When does the condition expression of a while loop get evaluated?
beginning of the loop
58
JavaScript Loops: When does the initialization expression of a for loop get evaluated?
once before the loop
59
JavaScript Loops: When does the condition expression of a for loop get evaluated?
after the initialization and before beginning each loop
60
JavaScript Loops: When does the final expression of a for loop get evaluated?
at the end of each the loop
61
JavaScript Loops: Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break;
62
JavaScript Loops: What does the ++ increment operator do?
it increases the value of the variable by one
63
JavaScript Loops: How do you iterate through the keys of an object;
for..in loop
64
JavaScript Forms: What event is fired when a user places their cursor in a form control?
focus
65
JavaScript Forms: What event is fired when a user's cursor leaves a form control?
blur
66
JavaScript Forms: What event is fired as a user changes the value of a form control?
input
67
JavaScript Forms: What event is fired when a user clicks the "submit" button within a
?
submit don't have submit handler on submit button, needs to be on the form, don't have click on submit button either
68
JavaScript Forms: What does the event.preventDefault() method do?
it prevents default behavior always use preventDefault() on forms
69
JavaScript Forms: What does submitting a form without event.preventDefault() do?
resets the page
70
JavaScript Forms: What property of a form element object contains all of the form's controls.
form.elements
71
JavaScript Forms: What property of a form control object gets and sets its value?
value property
72
JavaScript Forms: What is one risk of writing a lot of code without checking to see if it works so far?
you can't catch errors when they show up, so you have to go back and look for them
73
JavaScript View Swapping: What is the event.target?
it is the element the event interacted with
74
JavaScript View Swapping: What is the affect of setting an element to display: none?
it isn't visible and doesn't take up space (no longer part of the flow)
75
JavaScript View Swapping: What does the element.matches() method take as an argument and what does it return?
css selectors they return a boolean true if the element matches the element
76
JavaScript View Swapping: How can you retrieve the value of an element's attribute?
element.getAttribute( attributeName )
77
JavaScript View Swapping: At what steps of the solution would it be helpful to log things to the console?
each step, every line
78
JavaScript View Swapping: 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 have to write a new conditional for each tabs (and for future tabs)
79
JavaScript View Swapping: 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?
you would need to have individual conditional blocks
80
JavaScript and JSON: what is JSON?
JSON (JavaScript Object Notation) is a (text-based) data interchange format and it sends and stores information in computer systems.
81
JavaScript and JSON: What are serialization and deserialization?
serialization is when you turn an object in memory into a stream of bytes so you can do things like store it or transport it over a network (stringify) deserialization is the reverse: turns a stream of bytes into an object in memory - fetching a stream of bytes from network or storage and converting it back into the object (parse)
82
JavaScript and JSON: Why are serialization and deserialization useful?
they are easier to work with
83
JavaScript and JSON: How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
84
JavaScript and JSON: How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
85
JavaScript Local Storage: how do you store data in localStorage?
localStorage.setItem('keyName', 'keyValue')
86
JavaScript Local Storage: How do you retrieve data from localStorage?
localStorage.getItem('keyName')
87
JavaScript Local Storage: What data type can localStorage save in the browser?
string
88
JavaScript Local Storage: When does the 'beforeunload' event fire on the window object?
when the window, document, and its resources are about to be unloaded
89
JavaScript Custom Methods: What is a method?
function stored in a property, stored in an object
90
JavaScript Custom Methods: how can you tell the difference between a method definition and a method call?
it has a code block with a return
91
JavaScript Custom Methods: Describe method definition syntax (structure)
var nameOfObj = { nameOfMethod: function () { code block with return; } }
92
JavaScript Custom Methods: Describe method call syntax (structure)
nameOfObj.nameOfMethod()
93
JavaScript Custom Methods: How is a method different from any other function?
anObj.method() tied to an obj
94
JavaScript Custom Methods: What is the defining characteristic of Object-Oriented-Programming?
objects can contain both data (as properties) and behavior (as methods)
95
JavaScript Custom Methods: What are the four 'principles' of Object Oriented Programming?
Abstraction Encapsulation Inheritance Polymorphism
96
JavaScript Custom Methods: What is 'abstraction'?
when you remove (generalize) physical, spatial, and temporal details or attributes in the study of objects to focus on details that are more important [being able to work with (possibly) complex things in simple ways]
97
JavaScript Custom Methods: What does API stand for?
application programming interface
98
JavaScript Custom Methods: What is the purpose of an API?
to give programmers a way to interact with a system in a simplified, consistent way
99
JavaScript This: What is 'this' in JavaScript?
keyword that is an implicit parameter, the object that a method is called on
100
JavaScript This: What does it mean to say that 'this' is an "implicit parameter"?
it means that 'this' is available in the function's code block even though it wasn't included in the function's parameter list or declared with var/let/const
101
JavaScript This: When is the value of 'this' determined in a function; call time or definition time?
when the function is called
102
JavaScript This: 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 because it's not being called yet
103
JavaScript This: Given the above character object, what is the result of the following code snippet? Why? character.greet();
"It's-a-me, Mario!" because we're calling greet off of character and character obj has a firstName property with a value
104
JavaScript This: Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
"It's-a-me, undefined!" it says undefined because an object is not given so it default to windows and windows doesn't have a firstName property
105
JavaScript This: How can you tell what the value of 'this' will be for a particular function or method definition?
you can't know the value yet because this can only have a value when the function is being called, not in a function definition
106
JavaScript This: How can you tell what the value of 'this' is for a particular function or method call?
it would be the object to the left of the dot where the function is being called
107
JavaScript Prototypes: What kind of inheritance does the JavaScript programming language use?
prototype-based (prototypal)
108
JavaScript Prototypes: What is a prototype in JavaScript?
an object that contains properties and methods that can be reused by other objects
109
JavaScript Prototypes: 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?
they borrow the methods defined on a prototype object
110
JavaScript Prototypes: If an object does not have it's own property or method by a given key, where does JavaScript look for it?
a prototype object
111
JavaScript Constructors: What does the 'new' operator do?
1. create a blank, plain JavaScript object from scratch 2. points the blank JS obj's prototype to the constructor function's prototype property (if the prototype is an obj) Otherwise it stays as a plain obj with Object.prototype as its prototype 3. Executes the constructor function with the given arguments, binding the blank JS obj as the 'this' context 4. if the constructor function returns a non-primitive, the return value becomes the result of the whole new expression. Otherwise, it it doesn't return anything or returns a primitive, the blank JS obj is returned instead
112
JavaScript Constructors: What property of JavaScript functions can store shared behavior for instances created with 'new'?
.prototype
113
JavaScript Constructors: What does the instanceof operator do?
It tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object
114
JavaScript Timers: What is a "callback" function?
a function that is passed into another function as an argument, which is then invoked inside the outer function to complete a routine or action
115
JavaScript Timers: 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()
116
JavaScript Timers: How can you set up a function to be called repeatedly without using a loop?
setInterval()
117
JavaScript Timers: What is the default time delay if you omit the 'delay' parameter from setTimeout() or setInterval()?
immediate
118
JavaScript Timers: What do setTimeout() and setInterval() return?
an interval id
119
JavaScript Ajax: What is AJAX?
it is a technique for loading data into part of a page without having to refresh the entire page
120
JavaScript Ajax: What does the AJAX acronym stand for?
Asynchronous JavaScript and XML
121
JavaScript Ajax: which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
122
JavaScript Ajax: What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
'load'
123
JavaScript Ajax: Bonus Question, An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
they're both objects so they can use the prototype methods (addEventListener)