js Flashcards

1
Q

What is the purpose of variables?

A

store data; store value in variables that can be accessed; data that persists (accessible in the future; “data permanence”; saved for 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

using the keyword var

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

var keyword, name of the variable, assignment operator (equal sign), value of the variable

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, dollars, numbers (can’t start with a number), underscore

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

required to match to function/work

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

store data with text/series of characters; sequence of characters used to represent text

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

numeric data type; 64 bits of memory

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

logical data type that can have only the values true or false, i.e., boolean conditionals are often used to decide which sections of code to execute (such as in if statements) or repeat (such as in for loops); make decisions (do or don’t; yes or no)

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

What does the = equal sign operator mean in JavaScript?

A

assigning a value or something

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

reassign with new value

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

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

A

debugging purposes; gives context to what data types you are working with

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

Give five examples of JavaScript primitives.

A

string, number, boolean, undefined, null, symbol (produces an anonymous, unique value), bigint (aka long arithmetic, numeric data type; allows to process much greater numbers than can be fit in standard data types); all primitives are immutable (can’t be altered), that is not an object or method

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

What is string concatenation?

A

combination of two or more string values; can include concatenating to a number

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

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

A

math or concatenation

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

What data type is returned by comparing two values (< less than, > greater than, === strictly equal, etc)?

A

boolean

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

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

A

adds to the value to the right to the value to the left and the result is the new value

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

What are objects used for?

A

data type; store various keyed collections and more complex entities

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

What are object properties?

A

association between name and value

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

Describe object literal notation.

A

a variable assigned to an object illustrated by opening and closing braces with properties and their respective values within; an array of key:value pairs

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

delete operator using the keyword delete and the object with it’s respective property value that you want to delete

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 notation 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

store data with a specific index; ordered

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

Describe array literal notation.

A

square brackets

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 are objects but objects aren’t arrays

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

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

array.length; number of entries in the 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

type of object that can be called; set of reusable code

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 keyword, optional name for that function, parentheses around parameters (zero to infinity), curly braces for the function body, function body

31
Q

Describe the parts of a function call.

A

function name followed by parentheses; no arguments if not necessary

32
Q

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

A

arguments being passed through, function def has a function body

33
Q

What is the difference between a parameter and an argument?

A

parameter is a variable definition; argument is set data to be passed to the respective parameters

34
Q

Why are function parameters useful?

A

pass info to function

35
Q

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

A

produces a value in the function body to be sent outside the function for the function to be called when necessary

36
Q

Why do we log things to the console?

A

.

37
Q

What is a method?

A

a function stored within a property of an object;

38
Q

How is a method different from any other function?

A

.

39
Q

How do you remove the last element from an array?

A

array[array.length - 1]

40
Q

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

A

by calling the floor method of the math object function

41
Q

How do you generate a random number?

A

by calling the random method of the math object function

42
Q

How do you delete an element from an array?

A

using the pop method of the array object

43
Q

How do you append an element to an array?

A

using the push (append), using the (prepend)

44
Q

How do you break a string up into an array?

A

using the splice method

45
Q

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

A

they do not; console log output; strings are immutable (can’t be altered)

46
Q

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

A

a lot (around 30)

47
Q

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

A

no, i.e., splice method (we care about the work, not the return)

48
Q

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

A

a lot (~36)

49
Q

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

A

MDN

50
Q

Give 6 examples of comparison operators.

A

equal to, strictly equal to, less than, greater than, not equal to, greater than or equal to

51
Q

What data type do comparison expressions evaluate to?

A

strings, numbers, objects

52
Q

What is the purpose of an if statement?

A

compare

53
Q

Is else required in order to use an if statement?

A

no

54
Q

Describe the syntax (structure) of an if statement.

A

if keyword, comparison statement, body

55
Q

What are the three logical operators?

A

or, and, nullish

56
Q

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

A

use a logical operator(?)

57
Q

What is the purpose of a loop?

A

quick and easy way to do something repeatedly

58
Q

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

A

keeps the loop running or stops the loop

59
Q

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

A

when the same procedure is repeated multiple times

60
Q

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

A

before each pass through the loop

61
Q

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

A

once at the beginning of the loop (before anything)

62
Q

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

A

once before every iteration (before each)

63
Q

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

A

after each iteration; condition expression becomes false

64
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? which doesn’t work in a for…in loop

65
Q

What does the ++ increment operator do?

A

adds one to the operand and returns it

66
Q

How do you iterate through the keys of an object?

A

for… in loop, i.e., for keys in object, or using the keys method of object Object

67
Q

what are the parts of a for loop

A

[initialization] - this expression is where you initialize a variable that will be used as the counter; this counter will be updated in the incrementer and checked in the condition

[condition] - if this expression evaluates to true, we run another “cycle” of the loop, if false, we stop and exit the loop; we call each “cycle” in a loop an iteration.

[incrementer] - this expression is evaluated after every iteration of the loop; this step should bring the counter that was created in the [initialization] closer to a [conditional] that evaluates to false

68
Q

what are the steps of a for loop

A

step 1: initialize the counter

step 2: evaluate the condition - if it evaluates to false, exit the loop / if it evaluates to true, move forward to step 3

step 3: run all the code inside the body of the loop

step 4: increment the counter and go back to step 2

69
Q

what are the while loop parts

A

[initialization]

while ([conditional])
  // do something...

[incrementer]

70
Q

looping keywords

A

break (terminates the loop) and continue (skips the current loop iteration)

71
Q

what are some useful methods

A
Array.prototype.length
Array.prototype.indexOf(element)
Array.prototype.unshift(element)
Array.prototype.shift()
Array.prototype.push(element)
Array.prototype.pop()
Array.prototype.concat(other_array)
Array.prototype.slice(startIndex, endIndex)
Array.prototype.length (property)
Array.isArray(obj)
72
Q

useful string methods

A

string.split(separator) is a very helpful string method that splits a string into an array of substrings on the separator and returns the new array; does not change the original string

73
Q

What is fetch() and what does it return?

A
  • a promise that resolves to a response object
  • a promise which is fulfilled once the response is available
  • promise does not reject on HTTP errors
  • only rejects on network errors
  • use then handlers to check for HTTP errors
74
Q

What is the default request method used by fetch()?

A

get