JavaScript Flashcards

1
Q

What are objects used for?

A

Objects allow us to put data that makes sense together in one group/container.

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

What are object properties?

A

Data stored in an object.

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

Describe object literal notation.

A

var objectName = {
property: value,
otherProperty: otherValue
}

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

How do you remove a property from an object?

A

Using the delete operator.

delete object.propertyName

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

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

A

Dot Notation:
object.propertyName = “new value”

Bracket Notation:
object[‘properyName’] = “new value”

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

What is the purpose of variables?

A

Variables allow us to store data in memory to use later.

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

How do you declare a variable?

A

var variableName;

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

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

A

var variableName = value;

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

What characters are allowed in variable names?

A

letters, numbers (non-starting), $, _

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

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

A

When calling a variable, it must be exactly the name of that variable with exact casing.
variable and Variable are different variables.

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

What is the purpose of a string?
What is the purpose of a number?
What is the purpose of a boolean?

A

Strings store text data
Numbers store numbers, used for measurements, etc.
Booleans store true or false, used for yes and no situations

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

What does the = operator mean in JavaScript?

A

Assignment

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

How do you update the value of a variable?

A

varName = updatedValue;

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

What is the difference between null and undefined?

A

Null is a value for purposely blank, undefined means a variable has not been assigned a value

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

Labels give us context to what is being logged.

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

What is string concatenation?

A

The joining of strings

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

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

A

Addition, concatenation of strings

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

What data type is returned by comparing two values (, ===, etc)?

A

Boolean, with values true or false

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

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

A

Adds the right side value to the left side variable and reassigns that new value to the left side variable

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

What are arrays used for?

A

Arrays are used for storing lists of similar data.

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

Describe array literal notation.

A

[firstItem, secondItem]

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

How are arrays different from “plain” objects?

A

Arrays have order, item keys are indices.

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

What number represents the first index of an array?

A

0, arrays are 0 indexed

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

What is the length property of an array?

A

The length property is the number of items in the array

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

How do you calculate the last index of an array?

A

length-1

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

Why are function parameters useful?

A

Allows us to pass data in dynamically

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

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

A

1) Cause the function to produce a value

2) Exits the function, code in the code black after will not run

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

What is a function in JavaScript?

A

A callable object that contains reusable code

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

Describe the parts of a function definition.

A
  • function keyword
  • name
  • (parameters)
  • { code block
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Describe the parts of a function call.

A

functionName(arguments);

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

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

A

The definition has function keyword, code block, and paramters compared to arguments in the function call which has no function keyword and no code block

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

What is the difference between a parameter and an argument?

A

Parameters are placeholders in the function definition.

Arguments are actual values passed into a function call.

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

Why do we log things to the console?

A

For inspection, testing and spotting errors in code

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

What is a method?

How is a method different from any other function?

A

A function that is a property of an object.

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

How do you remove the last element from an array?

A

With the pop() method

array.pop()

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

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

How do you generate a random number?

A

Math.floor(Math.random( ) * (end - start) + 1 ) + start
(end-start) - gives range
+1 - because Math.random( ) is 1 (non-inclusive)

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

How do you delete an element from an array?

A

array.splice(start, deleteCount)

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

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

A

No, strings are immutable

Alter a string, then console.log the original string

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

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

A

Not always, functions may just be used to change a variable but not have to return anything.

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

Give 6 examples of comparison operators.

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

What data type do comparison expressions evaluate to?

A

boolean, true or false

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

What is the purpose of an if statement?

A

To execute a block of code if the condition is truthy

45
Q

Is else required in order to use an if statement?

A

No

46
Q

Describe the syntax (structure) of an if statement.

A

if (condition) {
code block
}

47
Q

What are the three logical operators?

A

&&, ||, !

48
Q

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

A

Parenthesis around each expression and joined with a logical operator.

49
Q

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

A

At the beginning of each iteration, before the code block runs.

50
Q

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

A

Before anything.

Once at the start of the loop.

51
Q

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

A

Before each.

Before each iteration.

52
Q

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

A

After each.

After the code block and before the next iteration’s condition is evaluated.

53
Q

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

A

break;

54
Q

What does the ++ increment operator do?

A

Increments the variable after an expression.

55
Q

How do you iterate through the keys of an object?

A

Using a for in loop.

56
Q

What is a “model”?

A

A representation of the actual thing

57
Q

Which “document” is being referred to in the phrase Document Object Model?

A

The HTML document

58
Q

What is the word “object” referring to in the phrase Document Object Model?

A

JavaScript objects

59
Q

What is the DOM?

A

Javascript object as a model of an HTML document.

Contains all the information about the HTML document but is NOT the HTML document

60
Q

What is a DOM Tree?

A

A representation of all HTML elements as their own DOM nodes.

61
Q

Why might you want to assign the return value of a DOM query to a variable?

A

To be able to reuse the queried value later on.

62
Q

What console method allows you to inspect the properties of a DOM element object?

A

console.dir()

63
Q

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

So all the HTML content prior can load first

64
Q

What does document.querySelector() take as its argument and what does it return?

A

Takes a CSS selector and returns the first element that matches that selector

65
Q

What does document.querySelectorAll() take as its argument and what does it return?

A

Takes a CSS selector and returns a NodeList of all matching element with that selector

66
Q

What is the purpose of events and event handling?

A

To allow creation of interactive and dynamic websites

67
Q

Are all possible parameters required to use a JavaScript method or function?

A

No,

68
Q

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

addEventListener() method

69
Q

What is a callback function?

A

a function passed into another function that is then invoked inside that function

70
Q

What object is passed into an event listener callback when the event fires?

A

The event object containing all information relevant to that specific event

71
Q

What is the event.target? If you weren’t sure, how would you check?

A

Target is the element we are dealing with currently, where it originated from.

72
Q

What is the textContent property of element objects?

A

The text content of a node and all descendent nodes

73
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

More complicated.

74
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

It’s better to have data stored in JavaScript if will be used again in JavaScript rather than querying for the element every time.

75
Q
What is the className property of element objects?
How do you update the CSS class attribute of an element using JavaScript?
A
The element's class attribute. 
targetElement.className = "class"
76
Q

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

A

Visually hides the elements, but programatically still there

77
Q

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

A

returns true or false if the string CSS selector would be valid to match that element

78
Q

How can you retrieve the value of an element’s attribute?

A

getAttribute() method

79
Q

At what steps of the solution would it be helpful to log things to the console?

A

every step

80
Q

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

Would have to create a new event listener for every view.

81
Q

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

Would have a long list of list of else if statements.

82
Q

What is JSON?

A

It is a format design to replicate the format of JavaScript objects.

83
Q

What are serialization and deserialization?

A

Serialization - process of turning an object in memory into stream of bytes (characters in a string)
Deserialization - turns stream of bytes into an object in memory

84
Q

Why are serialization and deserialization useful?

A

Makes it possible to transfer the data within the contents of an object or array.

85
Q

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

A

JSON.stringify( ) method

86
Q

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

A

JSON.parse( ) method

87
Q

How can you tell the difference between a method definition and a method call?

A

The method definition contains the keyword function and the code block.

The method call has the object followed by a dot and the method name with parenthesis and any args.

88
Q

Describe method definition syntax (structure).

A

Assigning a function to a property in an object or adding to an object.

89
Q

Describe method call syntax (structure).

A

object.method()

90
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects can contain both data (variables) and behavior (methods).

91
Q

What are the four “principles” of Object-Oriented Programming?

A

Abstraction
Encapsulation
Inheritance
Polymorphism

92
Q

What is “abstraction”?

A

Simplifying complex processes to into simple ways to interact with those complex things.

93
Q

What does API stand for?

What is the purpose of an API?

A

Application Programming Interface.

To give programmers a way to interact with a system in a simplified way.

94
Q

What is this in JavaScript?

A

Keyword referring to the object that it belongs to.

95
Q

What does it mean to say that this is an “implicit parameter”?

A

Means it is present in any function code block despite it not being in the parameter or declared with var keyword.

96
Q

When is the value of this determined in a function; call time or definition time?

A

During the call time.

Within the function definition, “this” does not have a value yet, it is nothing until call time.

97
Q

How can you tell what the value of this will be for a particular function or method definition?

A

You cannot tell the value of ‘this’ because it is created when the function is invoked.

98
Q

How can you tell what the value of this is for a particular function or method call?

A

When the function is invoked, ‘this’ is the object left of the dot. Otherwise ‘this’ does not exist yet and cannot have a value.

99
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal inheritance

100
Q

What is a prototype in JavaScript?

A

An object that contains properties and methods that other objects can use.

101
Q

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?

A

The prototype object has those methods that other objects, arrays, and numbers can delegate to.

102
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

Looks in the object prototype.

103
Q

What does the new operator do?

A

Creates a new instance of an object, sets the prototype of the object.
The ‘this’ becomes the new instance of the object
Runs the code.
Returns the object.

104
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

prototype

105
Q

What does the instanceof operator do?

A

Checks to see if the prototype of a an object matches the prototype specified.

pet instanceOf petConstructor, returns true

106
Q

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

Can use setTimeout() function.

107
Q

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

A

Can use setInterval( ) function.

108
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0 milliseconds.

109
Q

What do setTimeout() and setInterval() return?

A

They return timerID or intervalID