3/21 - 3/25/2022 Flashcards

1
Q

What is the purpose of variables?

A

To store 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 keyword “var, let, or const” and a 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 the “=” 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

A letter, dollar sign ($), underscore (_), or a number. It cannot start 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

The lowercase and uppercase of variable names are considered.
For example, “case” and “Case” are different and would be interpreted differently by the browser/computer.

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 numbers, perform mathematical calculations, and represent measurements

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 make decisions in code

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 “=” operator is the assignment operator; it is used to assign values to variables in JavaScript.

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 just assign it a new value using the same name and the “=” assignment operator.

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 that something is nonexistent or has an invalid object or address. “null” is assigned intentionally to say that “nothing is here”.
“undefined” is a primitive value that is automatically assigned to a variable that have 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

It makes debugging easier because the labels help you keep track of which variable is which.

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, numbers, boolean, undefined, and 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

The process of joining two or more strings together to create 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

The “+” operator can add numeric values or concatentate strings.

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

Booleans

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 current value of the variable (number or string) to the new variable (number or string) and re-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

Objects are used to group together properties and methods(functions) to create a model of something that exists in 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

Variable 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 comprised of the keyword used to create the variable, followed by the variable name for the object, followed by curly braces with content inside. The content is comprised of the properties and their respective 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’ keyword followed by the property of the object to be deleted using either dot or bracket notation.

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

Using dot 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

For storing list type data

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

Describe array literal notation.

A

Array literal notation consists of the variable declaration using a keyword (var, let, or const) followed by the assignment operator, followed by a set of brackets. The different data types (strings, numbers, arrays, objects) are stored inside the brackets separated by commas.

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 are ordered lists that are zero-indexed, while objects are unordered.

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

28
Q

What is the length property of an array?

A

It returns the number of items in the array.

29
Q

How do you calculate the last index of an array?

A

length - 1

30
Q

What is a function in JavaScript?

A

A special kind of object that is “callable”.

31
Q

Describe the parts of a function definition.

A
  1. the keyword “function”
  2. name of the function (optional)
  3. parameters
  4. opening “{“ to start the code block
  5. optional “return” statement
  6. closing “}” to end the code block
32
Q

Describe the parts of a function call.

A

The name of the function followed by an opening “(“ for the arguments, followed by any arguments, followed by a closing “)”.

33
Q

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

A

A function call is a “call” to execute the code block defined in the function defintion.
A function definition only defines the function; it does not execute the statements inside its code block.

34
Q

What is the difference between a parameter and an argument?

A

A parameter is used when defining a function. An argument is used when calling the function.

35
Q

Why are function parameters useful?

A

Because they act as placeholders where they can be replaced by arguments that are passed in when the function is called.

36
Q

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

A
  1. It returns a value that is the result of executing the statements inside the function’s code block.
  2. It stops execution at the “return” line. No code below this line is executed.
37
Q

Why do we log things to the console?

A

To keep track of what’s going on in our program/code and for debugging.

38
Q

What is a method?

A

A method is a function, which is a property of an object.

39
Q

How is a method different from any other function?

A

A method is a property of an object or an object reference to a function, while a function is itself an object.

40
Q

How do you remove the last element from an array?

A

The pop method

41
Q

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

A

Math.floor() function

42
Q

How do you generate a random number?

A

The Math.random() function

43
Q

How do you delete an element from an array?

A

Using the splice() method. The splice method can take 2 or 3 arguments with the first argument being the starting index and the second argument being the number of items to delete starting from the starting index.

44
Q

How do you append an element to an array?

A

Using the push() method and specifying the element(s) to add within the parentheses

45
Q

How do you break a string up into an array?

A

Using the split() method and specifying the pattern of the split within the parentheses

46
Q

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

A

No, strings are immutable. String methods return a new string.
To check, we could console log the original string to see if the original string has been changed by a string method.

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

Not in every situation. A certain situation may require the code block of a function to execute beyond the line where a ‘return’ keyword is used (Instead of using ‘return’ in such a situation, we could console log the statement to see what value is returned as a result of execution of the line). And a return value of a method may not always be necessary as it may only be needed for testing purposes.

It would also not be useful when you’re using a method like pop or shift where you don’t care about the return value because you’re just getting rid of the item in the array.

49
Q

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

A

~40

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
  1. >
  2. <
  3. ==
  4. > =
  5. <=
  6. ===
52
Q

What data type do comparison expressions evaluate to?

A

Booleans

53
Q

What is the purpose of an if statement?

A

To evaluate whether a condition is met . If it is met, the code block immediately following it is executed.

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

The keyword “if” followed by an condition with a comparison (and/or logical) operator within parentheses, followed by an opening “{“ for the code block, followed by one or more statements within the code block, followed by an “}” to close the code block.

56
Q

What are the three logical operators?

A
  1. &&
  2. ||
  3. !
57
Q

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

A

Using the && or || between the two expressions, which should each be surrounded by their own set of parentheses.

58
Q

What is the purpose of a loop?

A

To iterate over an array or the keys and/or values of properties of an object.

59
Q

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

A

To evaluate whether to execute another loop of the code block. If the condition is true, the loop will execute again; if not, it will stop execution.

60
Q

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

A

To perform an execution of the code block.

61
Q

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

A

Before the first execution and after each execution to see if the condition is still true.

62
Q

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

A

It is evaluated once before the loop begins.

63
Q

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

A

After the evaluation of the initialization expression and before each loop iteration afterward.

64
Q

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

A

After each loop iteration and right before the next evaluation of the condition expression

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

It adds one to the variable it is applied to. It is commonly applied to the counter variable of a for loop.

67
Q

How do you iterate through the keys of an object?

A

Using a ‘for…in’ loop with the syntax “${key}