JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store information to be accessed later on.

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

How do you declare a variable?

A

By using var , let, or const followed by the name of the variable.

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

By declaring a variable and then using the equal sign.

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, numbers, dollar signs

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

it means A and a are different

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

The purpose of a string is to work with text and can contain HTML markup.

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 have a value that can be calculated. But also to determine screen sizes or an amount of time for an element to do something.

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 help determine when someone needs to happen or not. 1 or 0.

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

The equal sign operator means assign.

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

You would simply type the variable again without the var and assign a new value to it.

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 is developer intended, while undefined is unintended.

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

There will be many logs when the codes get more in depth and things can get confusing. Simply, its for readability.

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, number, boolean, 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

A numerical value

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

What is string concatenation?

A

It’s when a string is added to another string or the value of a variable.

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

concatenation

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 (greater than, less than, ===, etc)?

A

Operands are being compared

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

It is the addition assignment. It adds the current value of something to the variable or number and the result of that expression is updated to the given variable.

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

What are objects used for?

A

Objects group together a set of variables and functions to create a model.

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

What are object properties?

A

Object properties are essentially variables.

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

Describe object literal notation.

A

An object literal notation contains an opening curly brace that holds key value pairs, followed by a closing curly brace.

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

How do you remove a property from an object?

A

By using the delete operator followed by the object name and the property name.

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

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

A

By typing the object name followed by the member operator (.) followed by the assignment operator (=), followed by the new property value.

By typing the object name followed by the property name inside the square brackets followed by the equal sign and the new property value.

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

What are arrays used for?

A

Arrays are used to hold things like a shopping list or something that are closely related that can be referenced by index numbers.

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

Describe array literal notation.

A

An array notion has an opening square bracket followed by the a list of strings separated by commas and then closed off with a closing square bracket.

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

How are arrays different from “plain” objects?

A

Arrays can be accessed by index numbers while objects require dot notations.

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

What number represents the first index of an array?

A

0 zero

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

What is the length property of an array?

A

The length property would just be array.length.

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

How do you calculate the last index of an array?

A

The last index of an array is array.length - 1.

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

What is a function in JavaScript?

A

A tool in javascript to write scripts that can be reused as many times as needed.

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

Describe the parts of a function definition.

A

A function definition has a function keyword and name that can be anonymous or named, followed by parenthesis for the parameters, followed by a curly brace for the code block that has code inside to execute the given function when called.

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

Describe the parts of a function call.

A

Function call executes the function that is previously defined. It would be the name of the function along with the parenthesis.

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

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

A

A function definition has a code block that can be used over and over. While calling a function would execute the definition.

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

What is the difference between a parameter and an argument?

A

A parameter is used when defining a function, while an argument is used when calling a function.

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

Why are function parameters useful?

A

Parameters are placeholders for the arguments so the function would be dynamic (reusable), instead of it being hard coded.

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

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

A

Return allows the function to produce a value and also prevents more code from being run.

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

Why do we log things to the console?

A

To check what the line of code is doing so we can see if it’s correct.

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

What is a method?

A

Method is a function which is a property of an object. Methods are built-in for javascript and usually have a purposeful return value.

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

How is a method different from any other function?

A

Methods are already built-in to the language. Other functions, we would need to define it.

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

How do you remove the last element from an array?

A

Array.pop()

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

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

How do you delete an element from an array?

A

Array.splice()

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

How do you append an element to an array?

A

Array.push(), Array.unshift(),

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

How do you break a string up into an array?

A

String.split()

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

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

A

You can log out the new variable if the string method was assigned.

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

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

A

a lot

48
Q

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

A

Not always useful, but there was a use when someone created it.

49
Q

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

A

a lot

50
Q

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

A

mdn

51
Q

Give 6 examples of comparison operators.

A

==, ===, !=, !==, >, =, <=

52
Q

What data type do comparison expressions evaluate to?

A

Boolean values.

53
Q

What is the purpose of an if statement?

A

If statements allow a statement to execute if the condition being compared is true.

54
Q

Is else required in order to use an if statement?

A

no.

55
Q

Describe the syntax (structure) of an if statement.

A

Keyword if followed by parenthesis. Inside is the condition thats being compared. Followed by a return value of some sort or action.

56
Q

What are the three logical operators?

A

logical and, logical or, logical not

57
Q

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

A

Using the logical operators.

58
Q

What is the purpose of a loop?

A

Loops are used to execute something over and over until the condition is met.

59
Q

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

A

The condition expression is our on and off setting for the loop.

60
Q

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

A

It refers to each time the loop is run and then repeated.

61
Q

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

A

It gets evaluated in the beginning after the while keyword.

62
Q

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

A

It gets evaluated in the beginning of a for loop.

63
Q

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

A

After the initialization expression and after the start of each iteration.

64
Q

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

A

After the condition express if it was met and the code block within the loop is executed.

65
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

66
Q

What does the ++ increment operator do?

A

The ++ adds one to the current value.

67
Q

How do you iterate through the keys of an object?

A

By using a for in loop.

68
Q

What is the event.target?

A

Refers to the object of the event that is occurring.

69
Q

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

A

It allows us to hide things from the html.

70
Q

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

A

it takes a CSS selector as a string

71
Q

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

A

element.getAttribute()

72
Q

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

A

From the very beginning.

73
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

.

74
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

.

75
Q

What is JSON?

A

JavaScript Object Notation

76
Q

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory to a stream of bytes to be stored.
Deserialization is the process of turning a steam of bytes back into an object.

77
Q

Why are serialization and deserialization useful?

A

Allows computers to send data to one another in an efficient way.

78
Q

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

A

JSON.stringify()

79
Q

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

A

JSON.parse()

80
Q

How to you store data in localStorage?

A

localStorage.setItem()

81
Q

How to you retrieve data from localStorage?

A

localStorage.getItem()

82
Q

What data type can localStorage save in the browser?

A

strings

83
Q

When does the ‘beforeunload’ event fire on the window object?

A

The beforeunload event occurs when the browser is attempting to close/unloaded.

84
Q

What is a method?

A

A function which is a property of an object.

85
Q

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

A

A method definition has the keyword function and the code block following it. A method call only has the argument inside of the method.

86
Q

Describe method definition syntax (structure).

A

A method definition would have the property name followed by the function keyword and its parameters. And then a code block that has the necessary code.

87
Q

Describe method call syntax (structure).

A

A method call would have the object followed by a period and the property after. And then parenthesis to hold the given arguments for that method call.

88
Q

How is a method different from any other function?

A

A method is a property thats defined within that object, while a normal function is a method of the global scope (window).

89
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects can contain both data (as properties) and behavior (as methods).

90
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

91
Q

What is “abstraction”?

A

Abstraction is the process of generalization for something that is much more complicated so it is easier to work with.

92
Q

What does API stand for?

A

Application Programming Interface

93
Q

What is the purpose of an API?

A

To allow a programmer a way to interact with a system in a simplified way.

94
Q

What is this in JavaScript?

A

This is an implicit parameter of all js functions.

95
Q

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

A

Means it is available in the code block even if it was never included in the parameter list.

96
Q

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

A

call time

97
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based or prototypal

98
Q

What is a prototype in JavaScript?

A

An object that contains properties and methods that can be used by other objects.

99
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

.

100
Q

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

A

.

101
Q

What does the new operator do?

A

.

102
Q

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

A

.

103
Q

What does the instanceof operator do?

A

The operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain. A boolean value is returned.

104
Q

What is a “callback” function?

A

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

105
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

By using the method setTimeout.

106
Q

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

A

By using the setInterval method.

107
Q

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

A

The default time delay is 0, which executes immediately.

108
Q

What do setTimeout() and setInterval() return?

A

They both return a timeoutID that can be used to cancel the timeout.

109
Q

What is AJAX?

A

A programming practice of building complex, dynamic, webpages using XMLHttpRequest.

110
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

111
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest

112
Q

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

A

load

113
Q

An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

They both of the same eventTarget prototype.

114
Q

What is Array.prototype.filter useful for?

A

The array.filter method will help create a new array with all the elements that pass the test in the provided function.

115
Q

What is Array.prototype.map useful for?

A

Array.map is useful for converting lists of data into another format. Examples are times for time zone to a different time zone and currency values.

116
Q

What is Array.prototype.reduce useful for?

A

Array.reduce is useful for condensing data into smaller data to interpret easier. Outputs a single value.