JS Flashcards

1
Q

What is the purpose of variables?

A

Variables are used to store information that will be used later

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

How do you declare a variable?

A

We declare a variable by using the var keyword followed by the variable
name, then assignment operator followed by a value

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

We use variable name, followed by the assignment
operator (=) followed by a variable value

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, underscore, and dollar signs, but
variables can not begin with a 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

It means uppercase and lowercase
letters has an affect on the word name. As an example, ”A” is different that ”a

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

Used for tasks involving text content or tasks involving words or
phrases

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

Used for tasks involving counting, adding, or mathematical operations,or anything that involves numbers

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

Used for true/false tasks or used for decision making

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

= is an assignment operator. It sets a variable to
equal something or update a variable’s value

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

We will use the assignment operator for the variable

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 means the value is nonexistent where undefined
means the variable has not been defined or the variable has just been declared

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

So we can know what the outputs are referring to

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

Give five examples of JavaScript primitives

A
  1. string
  2. number
  3. boolean
  4. undefined
  5. null
  6. symbol
  7. bigint
    2
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

numbers

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

What is string concatenation?

A

It is combining two strings into one string

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

this is used for string concatenation
and addition

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

this will add the number and then set the variable
equal to the result

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

What are objects used for?

A

Objects are a group of variables and functions used to create a model of
something from the real world

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 variables that are apart of an object

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

Describe object literal notation

A

Object literal notation is used to create an object. We start with a
var keyword followed by a variable name with the assignment operator and curly braces. Inside the
curly braces, we have a key and their value separated by a colon. Each key is separated by a comma

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

We would use the delete operator followed by the
object name, period, and the property we want to remove

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

to access the value of a property, we would use object, period, followed by the property name (object.newValue).
To update the value of an object property, we would used, object, open bracket, property name, close
bracket, assignment operator, and the new property value. (object[’property’] = newValue)

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 for storing data in an organized and predictable manner.
Each value is enumerated. Store a list of data in a set order

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

Describe array literal notation.

A

We start with a var keyword, followed by the array name, then
assignment operator, open bracket, values stored in the array in order, and close bracket. (var array
= [1,2,3])

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 differ from plain objects for arrays are ordered
where objects are not

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

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

It will give the number of items in an array

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

We will take the length of the array and subtract 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

Functions are a “chunk” of code that you can use over and over
again, rather than writing it out multiple times

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

function keyword, function name (optional), open curly
brace, code, return statement, and close curly brace

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

a function call is when we are calling a function to run their block
of code with arguments. We need the function name, and the arguments

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 call will use specific arguments where a function definition with have a general
parameter. Also, there is no curly braces in a function call or function keyword

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 in a function
definition where argument is used in 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

They are a placeholder for what kind of inputs the function will
take. They could give a clue into what the function wants as an argument and used for variance for
functions

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

The return statement causes the function to produce a value we can use in our program and 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

Why do we log things to the console?

A

So we can verify the outputs

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

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

How is a method different from any other function?

A

It is because they are within an object

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

We can use the pop() method of the array object
to remove the last element from an array

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

We can use the floor() method of the Math object

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

We can use the random() method of the Math object

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

We can use splice() method of the array object with a
start index followed by 1 item

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

We can use the push() method of the array object with an argument of the object we want to append

45
Q

How do you break a string up into an array?

A

We can use the split() method of the string object

46
Q

Do string methods change the original string?

A

How would you check if you weren’t sure? No. We can
check by console.logging the original string

47
Q

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

A

50

48
Q

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

A

No. Not in all cases. Like, the
pop() method will remove the last value of the array, but we may not care about the last value we
removed

49
Q

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

A

30 or 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

== (equal to), != (not equal to), > (greater than), < (less
than), === (strict equal to ), !==(not strict equal to), >= (greater than or equal to), <= (less than
or equal to)

52
Q

What data type do comparison expressions evaluate to?

A

boolean

53
Q

What is the purpose of an if statement?

A

They are used for decision making

54
Q

Is else required in order to use an if statement?

A

No, else statements are not required

55
Q

Describe the syntax (structure) of an if statement.

A

We start with an if keyword, followed by open
parentheses, a compassion expression, then a closed parentheses, followed by an open brace, with
something to happen if the condition is true, the a close brace.

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

We can use parentheses to separate the expressions and use && or ||

58
Q

What is the purpose of a loop?

A

To repeat a set of code until a certain condition is reached

59
Q

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

A

To give the loop a stopping point

60
Q

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

A

iteration means each time the loop code is ran

61
Q

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

A

It gets evaluated at the beginning of every iteration

62
Q

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

A

At the beginning before the loop.
It only happens one time

63
Q

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

A

At the beginning of each iteration

64
Q

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

A

At the end of each iteration

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

The break keyword

66
Q

What does the ++ increment operator do?

A

++ adds one to the variable and assign the new value to
the variable

67
Q

How do you iterate through the keys of an object?

A

We can use for in loops

68
Q

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

A

The focus event

69
Q

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

A

The blur event

70
Q

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

A

The input event

71
Q

What event is fired when a user clicks the ”submit” button within a ?

A

The submit event is
attached to the form element

72
Q

What does the event.preventDefault() method do?

A

The preventDefault() method of the Event interface
tells the user agent that if the event does not get explicitly handled, its default action should not be
taken as it normally would be. Prevent the default behavior of the event

73
Q

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

A

Without it, the page will automatically reload when the submit button is pressed

74
Q

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

A

The elements property

75
Q

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

A

The value property

76
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

Our code could not
work and it would be difficult to find where it went wrong

77
Q

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

A

So we can
verify the outputs are what we expect it to be

78
Q

What is the event.target?

A

This will gives us the most specific element the event is interacting with

79
Q

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

A

The display of the element will not appear
on the web page and removed from the document flow

80
Q

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

A

It takes CSS Selectors and returns true if the Element matches the selectors. Otherwise, false.

81
Q

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

A

We can use the getAttribute() method of
the element object. It takes a string of the name of the attribute

82
Q

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

A

Every time we changed
the view

83
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

We would need to use event listener for everything
button

84
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

We can write a conditional for every element in the loop

85
Q

What is JSON?

A

JSON is a text-based data format following JavaScript object syntax that can repre-
sent numbers, booleans, strings, null, arrays (ordered sequences of values), and objects (string-value
mappings) made up of these values (or of other arrays and objects)

86
Q

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory
into a stream of bytes so you can do stuff like store it on disk or send it over the network. Deserialization
is the reverse process: turning a stream of bytes into an object in memory.

87
Q

Why are serialization and deserialization useful?

A

They are useful for storing, transmitting, and retrieving data

88
Q

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

A

We can use JSON.stringify()
method

89
Q

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

A

We can use JSON.parse()
method

90
Q

How do you store data in localStorage?

A

We can use the setItem() method of the localStorage object

91
Q

How do you retrieve data from localStorage?

A

We can use the getItem() method of the localStorage
object

92
Q

What data type can localStorage save in the browser?

A

Strings

93
Q

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

A

The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible
and the event is still cancelable at this point

94
Q

What is a method?

A

A method is a function that is stored in a property of an object

95
Q

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

A

A method definition is located inside of an object literal, where a method call is begin call from an object

96
Q

Describe method definition syntax (structure).

A

We start with an object in object literal notation. Next,
we give the function a name, followed by a semicolon, followed by a function keyword and parenthesis,
followed by an opening curly brace and the function code block.

97
Q

Describe method call syntax (structure).

A

We start with an object. Then we use the object name,
followed by the name of the function, opening parenthesis, the arguments, and closing parenthesis

98
Q

How is a method different from any other function?

A

Methods are stored inside objects. They can not
be called outside of the object

99
Q

What is the defining characteristic of Object-Oriented Programming?

A

We need an object to store the data and behaviors of the object

100
Q

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

A

– Abstraction - The idea of generalizing details without needing a full understanding of the me-
chanics of how it actually functions
– Encapsulation - The idea of limiting access to data/methods that are stored within an object
– Inheritance - The mechanism of basing an object or class upon another object (prototype-based
inheritance) or class (class-based inheritance)
– Polymorphism - Polymorphism is the provision of a single interface to entities of different types
or the use of a single symbol to represent multiple different types.

101
Q

What is ”abstraction”?

A

Abstraction is used to generalize ideas without needing to understand the full mechanics of how something works

102
Q

What does API stand for?

A

Application programming interface (API) is a way for two or more computer
programs to communicate with each other

103
Q

What is the purpose of an API?

A

Application programming interface connects computers or pieces of
software to each other

104
Q

What is this in JavaScript?

A

This is an implicit parameter of all JavaScript functions

105
Q

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

A

By being an implicit parameter, it
means that it is available in a function’s code block even though it was never included in the function’s
parameter list or declared with var

106
Q

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

A

Call time

107
Q

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

A

the
value of this can be recognized as ”the object to the left of the dot” when the function is called (as a
method). If there is no value to the left of the dot when the function is called, then by default, this
will be the global window object. If you cannot see the function being called, then you do not know
what the value of this will be.

108
Q

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

A

the value of this can be recognized as ”the object to the left of the dot” when the function is called (as a method). If
there is no value to the left of the dot when the function is called, then by default, this will be the
global window object.