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
What is the length property of an array?
The length property is the number of items in the array
26
How do you calculate the last index of an array?
length-1
27
Why are function parameters useful?
Allows us to pass data in dynamically
28
What two effects does a return statement have on the behavior of a function?
1) Cause the function to produce a value | 2) Exits the function, code in the code black after will not run
29
What is a function in JavaScript?
A callable object that contains reusable code
30
Describe the parts of a function definition.
- function keyword - name - (parameters) - { code block }
31
Describe the parts of a function call.
functionName(arguments);
32
When comparing them side-by-side, what are the differences between a function call and a function definition?
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
33
What is the difference between a parameter and an argument?
Parameters are placeholders in the function definition. | Arguments are actual values passed into a function call.
34
Why do we log things to the console?
For inspection, testing and spotting errors in code
35
What is a method? | How is a method different from any other function?
A function that is a property of an object.
36
How do you remove the last element from an array?
With the pop() method | array.pop()
37
How do you round a number down to the nearest integer?
Math.floor()
38
How do you generate a random number?
Math.floor(Math.random( ) * (end - start) + 1 ) + start (end-start) - gives range +1 - because Math.random( ) is 1 (non-inclusive)
39
How do you delete an element from an array?
array.splice(start, deleteCount)
40
Do string methods change the original string? How would you check if you weren't sure?
No, strings are immutable | Alter a string, then console.log the original string
41
Is the return value of a function or method useful in every situation?
Not always, functions may just be used to change a variable but not have to return anything.
42
Give 6 examples of comparison operators.
``` > < >= <= == === ```
43
What data type do comparison expressions evaluate to?
boolean, true or false
44
What is the purpose of an if statement?
To execute a block of code if the condition is truthy
45
Is else required in order to use an if statement?
No
46
Describe the syntax (structure) of an if statement.
if (condition) { code block }
47
What are the three logical operators?
&&, ||, !
48
How do you compare two different expressions in the same condition?
Parenthesis around each expression and joined with a logical operator.
49
When does the condition expression of a while loop get evaluated?
At the beginning of each iteration, before the code block runs.
50
When does the initialization expression of a for loop get evaluated?
Before anything. | Once at the start of the loop.
51
When does the condition expression of a for loop get evaluated?
Before each. | Before each iteration.
52
When does the final expression of a for loop get evaluated?
After each. | After the code block and before the next iteration's condition is evaluated.
53
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break;
54
What does the ++ increment operator do?
Increments the variable after an expression.
55
How do you iterate through the keys of an object?
Using a for in loop.
56
What is a "model"?
A representation of the actual thing
57
Which "document" is being referred to in the phrase Document Object Model?
The HTML document
58
What is the word "object" referring to in the phrase Document Object Model?
JavaScript objects
59
What is the DOM?
Javascript object as a model of an HTML document. | Contains all the information about the HTML document but is NOT the HTML document
60
What is a DOM Tree?
A representation of all HTML elements as their own DOM nodes.
61
Why might you want to assign the return value of a DOM query to a variable?
To be able to reuse the queried value later on.
62
What console method allows you to inspect the properties of a DOM element object?
console.dir()
63
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
So all the HTML content prior can load first
64
What does document.querySelector() take as its argument and what does it return?
Takes a CSS selector and returns the first element that matches that selector
65
What does document.querySelectorAll() take as its argument and what does it return?
Takes a CSS selector and returns a NodeList of all matching element with that selector
66
What is the purpose of events and event handling?
To allow creation of interactive and dynamic websites
67
Are all possible parameters required to use a JavaScript method or function?
No,
68
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener() method
69
What is a callback function?
a function passed into another function that is then invoked inside that function
70
What object is passed into an event listener callback when the event fires?
The event object containing all information relevant to that specific event
71
What is the event.target? If you weren't sure, how would you check?
Target is the element we are dealing with currently, where it originated from.
72
What is the textContent property of element objects?
The text content of a node and all descendent nodes
73
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
More complicated.
74
Why is storing information about a program in variables better than only storing it in the DOM?
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
``` What is the className property of element objects? How do you update the CSS class attribute of an element using JavaScript? ```
``` The element's class attribute. targetElement.className = "class" ```
76
What is the affect of setting an element to display: none?
Visually hides the elements, but programatically still there
77
What does the element.matches() method take as an argument and what does it return?
returns true or false if the string CSS selector would be valid to match that element
78
How can you retrieve the value of an element's attribute?
getAttribute() method
79
At what steps of the solution would it be helpful to log things to the console?
every step
80
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?
Would have to create a new event listener for every view.
81
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?
Would have a long list of list of else if statements.
82
What is JSON?
It is a format design to replicate the format of JavaScript objects.
83
What are serialization and deserialization?
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
Why are serialization and deserialization useful?
Makes it possible to transfer the data within the contents of an object or array.
85
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify( ) method
86
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse( ) method
87
How can you tell the difference between a method definition and a method call?
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
Describe method definition syntax (structure).
Assigning a function to a property in an object or adding to an object.
89
Describe method call syntax (structure).
object.method()
90
What is the defining characteristic of Object-Oriented Programming?
Objects can contain both data (variables) and behavior (methods).
91
What are the four "principles" of Object-Oriented Programming?
Abstraction Encapsulation Inheritance Polymorphism
92
What is "abstraction"?
Simplifying complex processes to into simple ways to interact with those complex things.
93
What does API stand for? | What is the purpose of an API?
Application Programming Interface. To give programmers a way to interact with a system in a simplified way.
94
What is this in JavaScript?
Keyword referring to the object that it belongs to.
95
What does it mean to say that this is an "implicit parameter"?
Means it is present in any function code block despite it not being in the parameter or declared with var keyword.
96
When is the value of this determined in a function; call time or definition time?
During the call time. | Within the function definition, "this" does not have a value yet, it is nothing until call time.
97
How can you tell what the value of this will be for a particular function or method definition?
You cannot tell the value of 'this' because it is created when the function is invoked.
98
How can you tell what the value of this is for a particular function or method call?
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
What kind of inheritance does the JavaScript programming language use?
Prototypal inheritance
100
What is a prototype in JavaScript?
An object that contains properties and methods that other objects can use.
101
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?
The prototype object has those methods that other objects, arrays, and numbers can delegate to.
102
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
Looks in the object prototype.
103
What does the new operator do?
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
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
105
What does the instanceof operator do?
Checks to see if the prototype of a an object matches the prototype specified. pet instanceOf petConstructor, returns true
106
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?
Can use setTimeout() function.
107
How can you set up a function to be called repeatedly without using a loop?
Can use setInterval( ) function.
108
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 milliseconds.
109
What do setTimeout() and setInterval() return?
They return timerID or intervalID