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
Q

JavaScript Arrays:
Describe array literal notation

A

[item, item, etc]

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

JavaScript Arrays:
How are arrays different from ‘plain’ objects?

A

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)

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

JavaScript Arrays:
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

JavaScript Arrays:
What is the length property of an array?

A

property.length
get the number of items in the array

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

JavaScript Arrays:
How do you calculate the last index of an array?

A

subtract 1 from property.length

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

JavaScript Functions:
What is a function in JavaScript?

A

chunk of code that performs a task that returns something (most the time)

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

JavaScript Functions:
Describe the parts of a function definition

A

functionKeyword optionalFunctionName (parameters) {function code block optionalReturnStatement} end of function code block

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

JavaScript Functions:
Describe the parts of a function call

A

functionName(arg1, arg2, etc);

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

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

A

a function definition has the functionKeyword and a code block, function call does not

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

JavaScript Functions:
What is the difference between a parameter and an argument?

A

parameters are part of a function declaration and act as placeholders
arguments are part of function call and take the place of parameters

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

JavaScript Functions:
Why are function parameters useful?

A

they act as placeholders for arguments

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

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

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

JavaScript If:
Give 6 examples of comparison operators

A

strictly equal to (===), strictly not equal to (!==), greater than, less than, greater than or equal to, less than or equal to, equal to (==)

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

JavaScript If
What data type do comparison expressions evaluated to?

A

boolean

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

JavaScript If
What is the purpose of an if statement?

A

to make decisions

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

JavaScript If:
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
41
Q

JavaScript If:
Describe the syntax(structure) of an if statement?

A

if keyword, condition,

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

JavaScript If:
What are the three logical operators?

A

logical and (&&), logical or (||), logical not (!)

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

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

A

logical and
logical or

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

JavaScript Methods:
Why do we log things to the console?

A

logging things into the console helps with debugging, so we can see where the browser prints errors and warnings in our code

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

JavaScript Methods:
What is a method?

A

A method is a function which is a property of an object

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

JavaScript Methods:
How is a method different from any other function?

A

methods are associated with objects

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

JavaScript Methods:
How do you remove the last element from an array?

A

pop()

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

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

A

Math.floor()

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

JavaScript Methods:
How do you generate a random number?

A

Math.random()

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

JavaScript Methods:
How do you delete an element from an array?

A

splice()

51
Q

JavaScript Methods:
How do you append an element to an array?

A

push()

52
Q

JavaScript Methods:
How do you break a string up into an array?

A

str.split()

53
Q

JavaScript Methods:
Do string methods change the original string? How would you check if you weren’t sure?

A

doesn’t change the string
console.log to check

54
Q

JavaScript Loops:
What is the purpose of a loop?

A

Way to repeat a code block until the condition is no longer true.

55
Q

JavaScript Loops:
What is the purpose of a condition expression in a loop?

A

it creates a stopping point

56
Q

JavaScript Loops:
What does ‘iteration’ mean in the context of loops?

A

One completion of the loop code block

57
Q

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

A

beginning of the loop

58
Q

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

A

once before the loop

59
Q

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

A

after the initialization and before beginning each loop

60
Q

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

A

at the end of each the loop

61
Q

JavaScript Loops:
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break;

62
Q

JavaScript Loops:
What does the ++ increment operator do?

A

it increases the value of the variable by one

63
Q

JavaScript Loops:
How do you iterate through the keys of an object;

A

for..in loop

64
Q

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

A

focus

65
Q

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

A

blur

66
Q

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

A

input

67
Q

JavaScript Forms:
What event is fired when a user clicks the “submit” button within a <form>?

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
Q

JavaScript Forms:
What does the event.preventDefault() method do?

A

it prevents default behavior
always use preventDefault() on forms

69
Q

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

A

resets the page

70
Q

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

A

form.elements

71
Q

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

A

value property

72
Q

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

A

you can’t catch errors when they show up, so you have to go back and look for them

73
Q

JavaScript View Swapping:
What is the event.target?

A

it is the element the event interacted with

74
Q

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

A

it isn’t visible and doesn’t take up space (no longer part of the flow)

75
Q

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

A

css selectors
they return a boolean
true if the element matches the element

76
Q

JavaScript View Swapping:
How can you retrieve the value of an element’s attribute?

A

element.getAttribute( attributeName )

77
Q

JavaScript View Swapping:
At what steps of the solution would it be helpful to log things to the console?

A

each step, every line

78
Q

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?

A

you would have to write a new conditional for each tabs (and for future tabs)

79
Q

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?

A

you would need to have individual conditional blocks

80
Q

JavaScript and JSON:
what is JSON?

A

JSON (JavaScript Object Notation) is a (text-based) data interchange format and it sends and stores information in computer systems.

81
Q

JavaScript and JSON:
What are serialization and deserialization?

A

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
Q

JavaScript and JSON:
Why are serialization and deserialization useful?

A

they are easier to work with

83
Q

JavaScript and JSON:
How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

84
Q

JavaScript and JSON:
How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse()

85
Q

JavaScript Local Storage:
how do you store data in localStorage?

A

localStorage.setItem(‘keyName’, ‘keyValue’)

86
Q

JavaScript Local Storage:
How do you retrieve data from localStorage?

A

localStorage.getItem(‘keyName’)

87
Q

JavaScript Local Storage:
What data type can localStorage save in the browser?

A

string

88
Q

JavaScript Local Storage:
When does the ‘beforeunload’ event fire on the window object?

A

when the window, document, and its resources are about to be unloaded

89
Q

JavaScript Custom Methods:
What is a method?

A

function stored in a property, stored in an object

90
Q

JavaScript Custom Methods:
how can you tell the difference between a method definition and a method call?

A

it has a code block with a return

91
Q

JavaScript Custom Methods:
Describe method definition syntax (structure)

A

var nameOfObj = {
nameOfMethod: function () {
code block with return;
}
}

92
Q

JavaScript Custom Methods:
Describe method call syntax (structure)

A

nameOfObj.nameOfMethod()

93
Q

JavaScript Custom Methods:
How is a method different from any other function?

A

anObj.method()
tied to an obj

94
Q

JavaScript Custom Methods:
What is the defining characteristic of Object-Oriented-Programming?

A

objects can contain both data (as properties) and behavior (as methods)

95
Q

JavaScript Custom Methods:
What are the four ‘principles’ of Object Oriented Programming?

A

Abstraction
Encapsulation
Inheritance
Polymorphism

96
Q

JavaScript Custom Methods:
What is ‘abstraction’?

A

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
Q

JavaScript Custom Methods:
What does API stand for?

A

application programming interface

98
Q

JavaScript Custom Methods:
What is the purpose of an API?

A

to give programmers a way to interact with a system in a simplified, consistent way

99
Q

JavaScript This:
What is ‘this’ in JavaScript?

A

keyword that is an implicit parameter, the object that a method is called on

100
Q

JavaScript This:
What does it mean to say that ‘this’ is an “implicit parameter”?

A

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
Q

JavaScript This:
When is the value of ‘this’ determined in a function; call time or definition time?

A

when the function is called

102
Q

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);
}
};

A

nothing because it’s not being called yet

103
Q

JavaScript This:
Given the above character object, what is the result of the following code snippet? Why?

character.greet();

A

“It’s-a-me, Mario!” because we’re calling greet off of character and character obj has a firstName property with a value

104
Q

JavaScript This:
Given the above character object, what is the result of the following code snippet? Why?

var hello = character.greet;
hello();

A

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

JavaScript This:
How can you tell what the value of ‘this’ will be for a particular function or method definition?

A

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
Q

JavaScript This:
How can you tell what the value of ‘this’ is for a particular function or method call?

A

it would be the object to the left of the dot where the function is being called

107
Q

JavaScript Prototypes:
What kind of inheritance does the JavaScript programming language use?

A

prototype-based (prototypal)

108
Q

JavaScript Prototypes:
What is a prototype in JavaScript?

A

an object that contains properties and methods that can be reused by other objects

109
Q

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?

A

they borrow the methods
defined on a prototype object

110
Q

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

a prototype object

111
Q

JavaScript Constructors:
What does the ‘new’ operator do?

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

JavaScript Constructors:
What property of JavaScript functions can store shared behavior for instances created with ‘new’?

A

.prototype

113
Q

JavaScript Constructors:
What does the instanceof operator do?

A

It tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object

114
Q

JavaScript Timers:
What is a “callback” function?

A

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
Q

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?

A

setTimeout()

116
Q

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

A

setInterval()

117
Q

JavaScript Timers:
What is the default time delay if you omit the ‘delay’ parameter from setTimeout() or setInterval()?

A

immediate

118
Q

JavaScript Timers:
What do setTimeout() and setInterval() return?

A

an interval id

119
Q

JavaScript Ajax:
What is AJAX?

A

it is a technique for loading data into part of a page without having to refresh the entire page

120
Q

JavaScript Ajax:
What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

121
Q

JavaScript Ajax:
which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest

122
Q

JavaScript Ajax:
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

‘load’

123
Q

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?

A

they’re both objects so they can use the prototype methods (addEventListener)