JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store data needed for a script to do its job.

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

How do you declare a variable?

A

Variables are declared by writing the var keyword and variable name followed by a semicolon.

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

Variables are initialized by writing the assignment operator and value after the variable name.

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, underscores (_), and 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

Variable names that consist of the same characters but different capitalization are distinct (not the name).

(Also, capitalization should be consistent.)

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 store text (any set of 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

The purpose of a number is to store numerical values.

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

The purpose of a boolean is to express true or false statements (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

The = operator in Javascript means assignment (of a value or return to a variable).

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

Variables are updated by writing the variable name and assignment operator followed by the new value and semicolon.

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 represents a nonexistent object (an intentional placeholder for “empty”).

Undefined is automatically assigned to variables that have just been declared (JavaScript’s way of saying a variable is empty - does not have access/cannot create null).

Developers should not used undefined.

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

Labels assist with referencing what a value represents or where it is from in the code.

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.

(Also Big Int and Symbol)

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

An arithmetic operation returns a number.

*NaN - not a number (typeof number)

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

What is string concatenation?

A

String concatenation is joining two or more strings or characters.

Immutable - Unable to be mutated/changed

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 plus operator in JavaScript is used for either addition for arithmetic operations or concatenation for joining strings or characters.

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

Comparing two values returns the Boolean data type.

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

The plus-equals operator adds the value from the right side of the operator to the left side of the operator.

(x += 1; is the shorthand version of x = x + 1;)

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 for grouping together a set of variables and functions to represent something 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

Object properties are variables that are part 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

A comma-separated list of key-value pairs inside curly braces.

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

Properties are removed from an object by writing the delete operator/keyword followed by the object name an 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

The two ways to get or update the value of a property are 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

Arrays are used for listing a set of values that are related to each other.

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

Describe array literal notation.

A

A comma-separated list of values between square brackets.

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

The key for each value in an array is its index number instead of a property.

Values are added to arrays using methods.

Arrays have a length property.

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

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 returns the number of characters in a string or the number of elements 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

The last index of an array is calculated by evaluating the length property of the array minus one.

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 set of statements that performs a task or calculates a value. Functions are reusable and can be written once to handle many situations.

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
  • The function keyword
  • A function name (optional)
  • A comma-separated list of parameters surrounded by parenthesis
  • Start of the function’s code block
  • A return statement (optional)
    -The end of the function’s 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
  • A function’s name
  • A comma-separated list of arguments surrounded by parenthesis
33
Q

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

A

A function call does not have a function keyword or code block.

34
Q

What is the difference between a parameter and an argument?

A

A parameter is a placeholder variable in a function definition that has an unknown value.

An argument is a value passed when a function is called.

35
Q

Why are function parameters useful?

A

Function parameters help indicate what can or should be passed into the function when it is called.

36
Q

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

A
  • The function produces a value that can be used in the program.
  • Stops any subsequent code from running in the function’s code block
37
Q

Why do we log things to the console?

A

Testing, debugging, checking status, etc..

38
Q

What is a method?

A

A function that is a property of an object.

39
Q

How is a method different from any other function?

A

A method must be called using dot notation.

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

The floor method.

42
Q

How do you generate a random number?

A

The random method.

43
Q

How do you delete an element from an array?

A

The splice method.

44
Q

How do you append an element to an array?

A

The push method.

45
Q

How do you break a string up into an array?

A

The split method.

46
Q

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

A

String methods do not change the original string. You can check by testing on the console or checking the documentation.

47
Q

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

A

50 string methods.

48
Q

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

A

Return values may not always be necessary,

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 (Mozilla Developer Network)

51
Q

Give 6 examples of comparison operators.

A

>

- greater than =   - greater than or equal to <     - less than <=   - less than or equal to === - absolutely equal to !==  - strictly not equal to
52
Q

What data type do comparison expressions evaluate to?

A

Comparison expressions evaluate to the Boolean data type.

53
Q

What is the purpose of an if statement?

A

The purpose of an if statement is to guide a program to make decisions based on specified conditions.

(Checks whether a condition is true.)

54
Q

Is else required in order to use an if statement?

A

Else is not required to use an if statement.

55
Q

Describe the syntax (structure) of an if statement.

A

The if keyword, condition in parenthesis, opening curly brace for the code block, code to execute (if any), and the closing curly brace for the code block.

56
Q

What are the three logical operators?

A

&& - And
|| - Or
! - Not

57
Q

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

A

Each individual expression should be separated by a logical operator excluding not.

58
Q

What is the purpose of a loop?

A

The purpose of a loop is to repeatedly execute a block of code as long as the specified condition is true.

59
Q

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

A

The purpose of a condition expression in a loop is to check if the code block should be executed.

60
Q

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

A

“Iteration” in the context of loops means the repetition of the loop.

61
Q

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

A

The condition expression of a while loops gets evaluated before each iteration of the loop. If the expression evaluates to true, then the code block is executed.

62
Q

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

A

The initialization expression of a for loop gets evaluated once before the first iteration.

63
Q

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

A

The condition expression of a for loop gets evaluated after the final expression (if the second iteration an on).

64
Q

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

A

The final expression of a for loop gets evaluated at the end of each loop iteration. (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

The break statement exits a loop before its condition expression evaluates to false.

66
Q

What does the ++ increment operator do?

A

The increment operator increases a variable’s numerical value by 1.

67
Q

How do you iterate through the keys of an object?

A

The keys of an object can be iterated by using a for-in loop.

68
Q

What is a “callback” function?

A

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

69
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

The setTimeout() function.

70
Q

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

A

The setInterval() function.

71
Q

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

A

0 milliseconds (no delay).

72
Q

What do setTimeout() and setInterval() return?

A

They will return an ID that is a number data type.

73
Q

What is Array.prototype.filter useful for?

A

Returning a new array of elements that meet a specific criteria based on another array.

74
Q

What is Array.prototype.map useful for?

A

Performing a function on each array in an element.

75
Q

What is Array.prototype.reduce useful for?

A

Getting a single value that is cumulative of an array.

To collapse an array of elements into a final value.

76
Q

What must the return value of myFunction be if the following expression is possible?

myFunction()();

A

Another function which is immediately called.

“Function’s function is being called.”

“The return of myFunction is being called which is another function.”

77
Q

What does this code do?

const wrap = value => () => value;

A

Wrap puts a function around value and is not evaluated until the inner function is called.

78
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

When a function is defined.

79
Q

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

A

Lexical scoping.