JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store bits of data

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

How do you declare a variable?

A

With a variable keyword (var, let, const) followed by the variable name

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

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

A

With an assignment operator (=)

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

What characters are allowed in variable names?

A

letters, digits, underscores and dollar signs (CANNOT START WITH NUMBER)

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

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

A

upper and lowercase matter

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

What is the purpose of a string?

A

To store text data

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

What is the purpose of a number?

A

To store number data

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

What is the purpose of a boolean?

A

To identify true or false

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

What does the = operator mean in JavaScript?

A

Assignment operator

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

How do you update the value of a variable?

A

By calling again with the assignment operator followed by the new value

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

What is the difference between null and undefined?

A

Null usually a placeholder

Undefined points at valueless variables

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

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

A

Describes the variable or value being logged

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

Give five examples of JavaScript primitives.

A

String
Boolean
Object
Undefined
Null

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

What is string concatenation?

A

When two or more lines of strings are combined using the addition operator

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

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

A

Adds one value to another

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

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

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

A

Adds the value of the right 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

What are objects used for?

A

To represent real world objects

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

What are object properties?

A

Information about the object

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

How do you remove a property from an object?

A

With the delete operator

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

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

A

Dot and Bracket notation

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

What are arrays used for?

A

To store list data

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

Describe array literal notation.

A

var arrayName = [’’]

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

How are arrays different from “plain” objects?

A

Arrays have indexes objects dont

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

What number represents the first index of an array?

A

array[0]

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

What is the length property of an array?

A

Represents the number of properties in that array

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

How do you calculate the last index of an array?

A

array[array.length -1]

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 pack of code to reuse

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 funcName(parameter,/…/,parameter) {
code …/
return;
code …/
}

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

funcName(parameter,/…/,parameter);

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

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

Arguments are real values being passed to the function, while parameters are just placeholder names

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

Why are function parameters useful?

A

Specify what the argument should be

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

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

A

Returns the function when being called
Stops the code from running

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

Why do we log things to the console?

A

To check our work

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

What is a method?

A

Function of an object

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

How is a method different from any other function?

A

It’s a property of an object

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

How do you remove the last element from an array?

A

With the array.pop(); method

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

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

A

With the Math.floor() method

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

How do you generate a random number?

A

With the Math.random(); method

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

How do you delete an element from an array?

A

With the array.splice(index,amount);

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

How do you append an element to an array?

A

With the push(); method

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

How do you break a string up into an array?

A

With the split() method

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

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

A

They dont

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

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

A

Around 50

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

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

A

No, you may use it later on

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

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

A

40-50

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

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

A

mdn

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

What data type do comparison expressions evaluate to?

A

Booleans

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

What is the purpose of an if statement?

A

To execute a block of code when the condition is met or not

52
Q

Is else required in order to use an if statement?

A

else

53
Q

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

A

&& ||

54
Q

What is the purpose of a loop?

A

Easy way to do something repeatedly

55
Q

What is the purpose of a condition expression in a loop?

A

To let it know when to start and stop

56
Q

What does “iteration” mean in the context of loops?

A

To repeat

57
Q

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

A

At the beginning

58
Q

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

A

At the very start

59
Q

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

A

After every initialization and after every loop

60
Q

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

A

After the iteration

61
Q

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

A

The Break; Key

62
Q

What does the ++ increment operator do?

A

Increment the value by one

63
Q

How do you iterate through the keys of an object?

A

With a for in loops

for ( var prop in obj ) {
code
}

64
Q

Why do we log things to the console?

A

To keep track that everything is working.

65
Q

What is a “model”?

A

A “model” is a memory saved model created with nodes representing an HTML element (DOM tree)

66
Q

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

A

The HTML document currently being worked on

67
Q

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

A

DOM Tree nodes

68
Q

Give two examples of document methods that retrieve a single element from the DOM.

A

getElementById()
querySelector()

69
Q

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

querySelectorAll()

70
Q

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

A

To refer back to it

71
Q

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

A

console.dir()

72
Q

Why would

 tag need to be placed at the bottom of the HTML content instead of at the top?
A

The HTML needs to be able to run first

73
Q

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

A

Uses a CSS class selector and returns the first matching element

74
Q

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

A

Uses a CSS selector and returns all matching elements

75
Q

What is a DOM Tree

A

A tree model of all the elements of an HTML document

76
Q

Why do we log things to the console?

A

To make sure everything is working

77
Q

What is the purpose of event handling?

A

They allow you to indicate which event you are waiting for on any particular elements.

78
Q

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

A

No

79
Q

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

A

element.onevent = functionName;

80
Q

What is a callback function?

A

A function being passed into another function as an argument

81
Q

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

A

The event object

82
Q

What is event.target? If you weren’t su re, how would you check? Where could you get more information about it?

A

Refers to the event target

83
Q

What is the className property of element objects?

A

Class Attribute

84
Q

How do you update the CSS class attribute of an element using JavaScript?

A

By setting the new value to the element.className property using the assignment operator

85
Q

What is the textContent property of element objects?

A

Text content of an HTML element

86
Q

How do you update the text within an element using JavaScript?

A

By setting the new text to the element.textContent property using the assignment operator

87
Q

Is the event parameter of an event listener callback always useful?

A

Yes it allows you to know that the listener is working but not always required

88
Q

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

A

Harder, there wouldnt be an easier way to compare the number of clicks to the required clicks so the button can change

89
Q

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

A

Storing them in variables allows for easy access when referring back to them and it makes it easier to keep track of.

90
Q

What is a method?

A

A method is a function which is a property of an object. There are two types of methods: instance methods (built in) and static methods (called directly on an object constructor)

91
Q

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

A

A me

92
Q

Describe method definition syntax (structure).

A

First have an anonymous function being assigned to an object property

93
Q

Describe methods call syntax (structure)

A

object.property(parameter)

94
Q

How is a method different from any other function?

A

Method is associated to an object

95
Q

What is the defining characteristic of Object-Oriented programming?

A

A programming paradigm based on the concept of “objects”, which can contain data and code. The data is in the form of fields (attributes/properties) and the code is in. the form of procedures (methods)

96
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

97
Q

What is “abstraction”?

A

Being able to work with (possible) complex things in simple ways.

98
Q

What does API stand for?

A

Application Programming Interface.

99
Q

What is the purpose of an API?

A

It’s a way for two or more computers to talk to one another.

100
Q

What is this in JavaScript?

A

The value of this depends on in which context it appears: function, class, or global

101
Q

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

A

It is included in a function’s code block even though it was never included in the function’s parameter list or declared with var.

102
Q

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

A

Call Time

103
Q

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

The Window because the function hasn’t been called yet

104
Q

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

The result would be “It’s-a-mi, Mario!”

105
Q

Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();

A

The result is “It’s-a-me, undefined!”

105
Q

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

A

You won’t know only assume

106
Q

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

A

By looking at the left of the dot

107
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype inheritance

108
Q

What is a prototype in JavaScript?

A

Contains functionally to reuse

109
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on string, arrays, and numbers?

A

Inherited from the prototype chain

110
Q

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

A

Prototype

111
Q

What does the new operator do?

A

Lets developers create an instance of user-defined object type of one of the built-in object types that has a constructor function.

112
Q

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

A

The Prototype

113
Q

What dies the instanceof operator do?

A

Tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.

114
Q

What is a “callback” function?

A

A callback function is a function passed into another function as an argument.

115
Q

Besides adding an event listener callback function to an element or the document, what us one way to delay the execution of a JavaScript function until some point in the future?

A

setTimeout()

116
Q

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

A

setInterbal()

117
Q

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

A

0

118
Q

What do setTimeout() and setInterval() return?

A

The code/function in a delayed time

119
Q

in JavaScript, when is scope determined?

A

When it parses through

120
Q

What allows JavaScript to “remember” values from their surroundings?

A

A closure

121
Q

What values does a closure contain?

A

All variables and functions in its scope

122
Q

When is a closure created?

A

Every time a function is created

123
Q

How can you tell if a function will be created as a closure?

A

If it needs any variables outside of itself

124
Q

In React, what is one important case where you need to know when a closure is created?

A

When there’s a useEffect.
if you have a function that is a dependency in your useEffect, you have to care if a closure was created.

125
Q

What is a closure?

A

The key to remember is that when a function gets declared, it contains a function definition and a closure. The closure is a collection of all the variables in scope at the time of creation of the function.