JavaScript Flashcards

1
Q

What is the purpose of variables?

A

The purpose of variables is to “remember”/store values/information. (Used to represent values in your scripts that are likely to change.)

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

How do you declare a variable?

A

Use the var keyword before the name of the 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

Use the equal sign 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

The name can contain letters, numbers, a dollar sign ($), or an underscore (_), but it must not 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

A variable name with lowercase letters will not be the same as the same variable name with uppercase. (eg. score and Score would be different variable names),and it is bad practice to create two variables that have the same name using different cases.

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 assign/store alphanumeric values as a text value to a variable

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 numeric characters and allow us to do mathematical calculations.

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

Booleans give/represent a true or false value

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

It is an assignment operator used to assign a value 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

Just use the variable name and assign the new value for that attribute.

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

A null value is intentionally created to be empty (represents a reference that typically points to a nonexistent or invalid object or address). Undefined is empty by nature and is automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.

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 add clarity to the output, in particular to aid in debugging.

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, undefined, bigint, 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

A numeric value

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

What is string concatenation?

A

Two or more strings joined with the string operator (+).

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 is used for addition with numerical values and for string concatenation, joining strings on either side of it.

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

A boolean value will be returned

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” (addition assignment) operator takes the original value of the variable and concatenates with a new variable, then reassigns itself back to the original 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 group together a set of variables and functions to create a model of something you would recognize 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

They are variables that tell us about the object. (Expressed in key:value pairs)

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

Describe object literal notation.

A
var varName = {
  property:"value", 
  property:"value",
  property:"value",
};
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

Use the Delete keyword and then use dot notation to identify the property or method you want to remove from the object.

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

By using the dot notation or square brackets → object.property_name = ‘(new)property_value’; or object[‘property_name’] = ‘(new)property_value’;

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

What are arrays used for?

A

Lists or sets of values that are related to each other, anything that is numerically indexed

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

Describe array literal notation.

A

Var variable_name = [a, b, c, d]
Var keyword with the name of the variable followed by the equals assignment operator, a square bracket containing the values, followed by a closing square bracket

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 is its index number

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 holds the number of items (key:value pairs) in an array.

29
Q

How do you calculate the last index of an array?

A

Array.length - 1

30
Q

What is a function in JavaScript?

A

A function is a block of code designed to perform a particular task, and it allows for you to execute it as many times as you want later in your code.

31
Q

Describe the parts of a function call.

A

The function’s name, then a comma-separated list of zero or more arguments surrounded by () parentheses.

32
Q

Describe the parts of a function call.

A

The function’s name, then a comma-separated list of zero or more arguments surrounded by () parentheses.

33
Q

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

A

A function definition uses the function keyword, has parameters and a block of code to execute, while a function call passes in arguments.

34
Q

What is the difference between a parameter and an argument?

A

When we define a function, we declare parameters and then when we call a function, we pass in arguments. A parameter is like a placeholder variable whose value is not known until we call the function and pass an argument.

35
Q

Why are function parameters useful?

A

They act as placeholders so you change the output by only having to pass in different arguments in their place when calling the function, thus, you don’t have to write the whole code block over again each time you want to use the function.

36
Q

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

A

A return statement causes the function to produce a value, and exits the function so no code following the return statement gets executed.

37
Q

Why do we log things to the console?

A

The console log function is mainly used for code debugging as it logs/prints the output to the console.

38
Q

What is a method?

A

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

39
Q

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

A

36 / 38 if including 2 experimental (50 including deprecated string methods)

40
Q

How do you remove the last element from an array?

A

The pop() method removes the last element from an array and returns that element. (This method changes the length of the array.)

41
Q

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

A

By using the Math.floor() function: Math.floor()

The return value is a number representing the largest integer less than or equal to the specified number.

42
Q

How do you generate a random number?

A

By calling the random method of the Math object: Math.random()

43
Q

How do you delete an element from an array?

A

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place

44
Q

How do you append an element to an array?

A

The push() method adds one or more elements to the end of an array and returns the new length of the array.

45
Q

How do you break a string up into an array?

A

The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array.

46
Q

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

A

No, methods don’t modify the original string, a new string is returned. Check by logging the original string variable to the console.

47
Q

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

A

MDN

48
Q

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

A

No, some functions don’t return any value.

Generally, a return value is used where the function is an intermediate step in a calculation of some kind.

49
Q

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

A

36 / 38 if including 2 experimental

50
Q

How is a method different from any other function?

A

A method is associated with an object, while a function is not.

51
Q

Give 6 examples of comparison operators.

A

> , =, <=, ==, !=, ===, !===

52
Q

What data type do comparison expressions evaluate to?

A

Boolean values (a single value- true or false)

53
Q

What is the purpose of an if statement?

A

To evaluate a condition- values/variables (the operands)- and if the condition/ or conditions (>=, <=) is met, then your code will execute one or more statements (else your code will do something different).

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 if keyword, followed by the condition in parenthesis with a comparison operator, and then an opening curly brace for the code block; on the next line, is the code to execute if value is true, and on the next line is 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

By using the && or || logical operators.

58
Q

What is the purpose of a loop?

A

To quickly and easily repeat an action any number of times without having to repeat the same line of code.

59
Q

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

A

It determines if the statement should be executed (if the condition is true), and determines when the loops is terminated (if the condition is false).

60
Q

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

A

The number of times it repeats/ iterates- each time the loop is passed through

61
Q

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

A

Before each pass through the loop.

62
Q

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

A

One time before the execution of the code block.

63
Q

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

A

Each time before the code block is executed.

64
Q

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

A

Every time after the code block has been executed.

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

The increment operator increases the value of a variable/operand by 1 and reassigns the updated value to the original variable.

67
Q

How do you iterate through the keys of an object?

A

By using a for…in loop