JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To remember data for future reference.

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

How do you declare a variable?

A

Write down keyword (var) to declare that 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 using a single = sign, (= meaning assignment).

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, $, _ anywhere and numbers ,but number needs to be at the end.

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

JavaScript does not consider lowercase and uppercase the same.

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

A way to hold a sequence of characters represented with letter characters.

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 numbers for calculation.

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

It allows us to render what is or isn’t.

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

To assign a thing.

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

No keyword is necessary.

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 can only be assigned and not generated by JavaScript, undefined comes from JavaScript.

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

To know what you are looking at specifically.

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, null, and undefined.

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 number.

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

What is string concatenation?

A

Any type of values being added to a string which results in 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

It can concatenate or be used for 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

It adds the value to the variable and assigns that 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 group together a set of properties, variables and functions to give it grouping in one location.

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

What are object properties?

A

The piece of data represented by the key and value.

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

Describe object literal notation?

A

The data inside the {} for example: properties or key and values.

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

With the delete operator and . name of the property

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

You can use dot notation or bracket notation.

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

What are arrays used for?

A

Good for rendering a list of data of any length and where the order is important or unimportant.

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

Describe array literal notation.

A

Opening bracket and closing bracket with any number of data types inside the array.

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

All arrays have a length property while objects do 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

Number 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

True count of how many items are in that 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

Subtract 1 from the length property of an array.

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

What is a function in JavaScript?

A

To group a series of statements together to preform a specific task.

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, name for the function, parameters in a set of (), and a code block {}.

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 name ().

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

There is no code block in a call and the 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

Arguments are values provided when a function is called and parameter are values provided when a function is defined.

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

Why are function parameters useful?

A

Parameters take in values and place them inside the function so that you can reuse the function instead of making multiple set of code for each value

36
Q

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

A

stops the function entirely and gives you a value to wherever the function is called

37
Q

Give 6 examples of comparison operators.

A

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

38
Q

What data type do comparison expressions evaluate to?

A

boolean

39
Q

What is the purpose of an if statement?

A

It allows us to make a choice

40
Q

Is else required in order to use an if statement?

A

no it is not

41
Q

Describe the syntax (structure) of an if statement.

A

start with if then parenthesis and curly braces then your return statement inside then a else or else/if statement with a return

42
Q

What are the three logical operators?

A

&& (and), || (or), ! (not)

43
Q

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

A

using &&, or ||

44
Q

Why do we log things to the console?

A

to debug and see whats going on or to better understand what is happening

45
Q

What is a method?

A

function which is the value of an object stored

46
Q

How is a method different from any other function?

A

methods are attributed to an object and called by attaching a dot ( . ) to the object while function you can just call

47
Q

How do you remove the last element from an array?

A

by using the .pop method that goes off an array object

48
Q

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

A

the floor method takes it down to the nearest integer

49
Q

How do you generate a random number?

A

the random method for the object math

50
Q

How do you delete an element from an array?

A

the splice method for the array object with the argument index number to know where to delete from

51
Q

How do you append an element to an array?

A

the push method of the array object to add it to the end of an array

52
Q

How do you break a string up into an array?

A

the split method of the string with the argument string space (‘ ‘)

53
Q

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

A

it does not change the string and you can check by using the log method for the console object

54
Q

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

A

no

55
Q

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

A

mdn

56
Q

What is the purpose of a loop?

A

to repeat a block of code until a condition is no longer met

57
Q

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

A

the condition is there to stop the loop when it is not met

58
Q

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

A

one time the code block in the loop runs

59
Q

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

A

before each iteration

60
Q

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

A

from the beginning and just once

61
Q

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

A

after the initialization and before each iteration of the code block

62
Q

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

A

at the end of each iteration, the final expression is what continues the loop

63
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 is how you escape a loop, break is used when you are looking for one value

64
Q

What does the ++ increment operator do?

A

increases the value by 1

65
Q

How do you iterate through the keys of an object?

A

using for in loop

66
Q

What is the event.target?

A

element you are interacting with

67
Q

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

A

makes element not visible, but still exists (no longer part of the flow or have no visual appearance)

68
Q

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

A

takes css selector and returns a boolean and whether the element matches the selector

69
Q

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

A

getAttribute(name of attribute) method

70
Q

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

A

every new line of code or expression

71
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

you would have to have an individual conditional for each view and tab

72
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
73
Q

What is JSON?

A

text-based data format following JavaScript object syntax

74
Q

What are serialization and deserialization?

A

serialization is converting data into a stream of bytes and deserialization is the opposite

75
Q

Why are serialization and deserialization useful?

A

serialization sends data easily while deserialization converts back that data back to an object so that it is easy to work with

76
Q

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

A

JSON.stringify() method

77
Q

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

A

JSON.parce() method

78
Q

How do you store data in localStorage?

A

localStorage.setItem(name(keyName), value(keyValue)) method

79
Q

How do you retrieve data from localStorage?

A

localStorage.getItem(keyName) method

80
Q

What data type can localStorage save in the browser?

A

string data

81
Q

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

A

when the window, the document and its resources are about to be unloaded or when the page closes (close page, refresh page, or)

82
Q

In JavaScript, when is scope determined?

A

when it parses the code

83
Q

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

A

a closure

84
Q

What values does a closure contain?

A

all variables and functions within the closures parent scope

85
Q

When is a closure created?

A

everytime a function reference is created and captured at run time

86
Q

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

A

if it needs any variables outside of itself

87
Q

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

A