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 don’t include “labels” it can get confusing
labels describe the variable or value being logged

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

it’s when you join two or more strings to create one new string
(if you concatenate other data types with a string, it’ll be a 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 strings together

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 that is recognizable 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 keyword 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

they are used to store a list of values/data
(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

arrayVariable.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 the array’s 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)
{ (opening curly brace for the function code block)
function code block optionalReturnStatement
} (closing curly brace for the 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);
- zero or more arguments separated by commas inside parenthesis

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);
- zero or more arguments separated by commas inside parenthesis

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 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
38
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
39
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
40
Q

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

A

pop() method

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

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

A

splice()

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

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

A

push()

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

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

A

str.split()

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

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

JavaScript Methods:
Roughly how many string methods are there according to the MDN Web docs?

A

36

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

JavaScript Methods:
Is the return value of a function or method useful in every situation?

A

no

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

JavaScript Methods:
Roughly how many array methods are there according to the MDN Web docs?

A

38

50
Q

JavaScript Methods:
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

51
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 (==)

52
Q

JavaScript If
What data type do comparison expressions evaluated to?

A

boolean

53
Q

JavaScript If
What is the purpose of an if statement?

A

(to make decisions)
evaluates a condition and
if the condition is true then whatever is in the code block gets executed

54
Q

JavaScript If:
Is else required in order to use an if statement?

A

no

55
Q

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

A

ifKeyword (condition) {
cod to execute
)

56
Q

JavaScript If:
What are the three logical operators?

A

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

57
Q

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

A

logical and
logical or

58
Q

JavaScript Loops:
What is the purpose of a loop?

A

It’s a way to repeat a code block until the condition is no longer true.

59
Q

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

A

it creates a stopping point

60
Q

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

A

One completion of the loop code block

61
Q

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

A

beginning of the loop

62
Q

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

A

once before the loop

63
Q

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

A

after the initialization and before the code runs

64
Q

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

A

at the end of each the loop

65
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;

66
Q

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

A

it increases the value of the variable by one

67
Q

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

A

for..in loop

68
Q

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

A

focus

69
Q

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

A

blur

70
Q

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

A

input

71
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

72
Q

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

A

it prevents default behavior
always use preventDefault() on forms

73
Q

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

A

resets the page

74
Q

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

A

form.elements

75
Q

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

A

value property

76
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

77
Q

JavaScript Forms
What is an advantage of having your console open when writing a JavaScript program?

A

you can catch errors early/when they happen

78
Q

JavaScript View Swapping:
What is the event.target?

A

it is the element the event interacted with

79
Q

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

A

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

80
Q

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

A

a css selector
and returns a boolean
true if the element matches the element

81
Q

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

A

the .getAttribute() method

element.getAttribute( attributeName )

82
Q

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

A

each step, or every line

83
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 event handlers for each new tab or view (and for any future tabs or views)

84
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 write conditionals for each view

85
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.

86
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)

87
Q

JavaScript and JSON:
Why are serialization and deserialization useful?

A

they are easier to work with

88
Q

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

A

JSON.stringify()

89
Q

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

A

JSON.parse()

90
Q

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

A

with the Storage.setItem() method

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

91
Q

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

A

with the Storage.getItem() method

localStorage.getItem(‘keyName’)

92
Q

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

A

JSON strings

93
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
(unload is when you close tab, unload data)

94
Q

JavaScript Custom Methods:
What is a method?

A

it is a function stored in a property, which is stored in an object

95
Q

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

A

a method definition has a function keyword, parameters, code block with a return

96
Q

JavaScript Custom Methods:
Describe method definition syntax (structure)

A

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

97
Q

JavaScript Custom Methods:
Describe method call syntax (structure)

A

nameOfObj.nameOfMethod()
with arguments in the parenthesis if needed

98
Q

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

A

it is inside, belongs to an object

99
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)

100
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

101
Q

JavaScript Custom Methods:
What is ‘abstraction’?

A

being able to work with (possibly) complex things in simple ways

when you remove (generalize) physical, spatial, and temporal details or attributes in the study of objects to focus on details that are more important

102
Q

JavaScript Custom Methods:
What does API stand for?

A

application programming interface

103
Q

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

A

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

104
Q

JavaScript This:
What is ‘this’ in JavaScript?

A

the object that a method is called on

105
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
(determined when the function is called. doesn’t exist until then)

106
Q

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

A

when the function is called

107
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

108
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 of ‘Mario’

109
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

110
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

111
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

112
Q

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

A

prototype-based (prototypal)

113
Q

JavaScript Prototypes:
What is a prototype in JavaScript?

A

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

114
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
(through prototypal inheritance)

115
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

116
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
117
Q

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

A

.prototype

118
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
returns a boolean value

119
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

120
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()

121
Q

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

A

setInterval()

122
Q

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

A

0, immediate

123
Q

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

A

an interval id
that can be passed into clearTimeout() or clearInterval()