JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store data types to later recall that information.

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 var, let, const.

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

They can contain letters, numbers, dollar signs, or an underscore, but numbers cannot be the first character.

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 are different if they have different letters capitalized or lower cased.

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

Strings can be used when working with any kind of 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

To be able to give a variable a numeric data type for math.

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 state whether a variable is true or false in order to compare.

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 means to assign a value to a variable. For the variable to contain or hold this value.

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 assign it to a different value.

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

It is a value that is purposely left ambiguous and generally leads to an object. Undefined values are variables that do not have a value.

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

The console can display exactly what it is being logged.

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

Give five examples of JavaScript primitives.

Exercise

A

Numbers, strings, 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

The result of the mathematical operation is returned and contained in the variable, which is numeric.

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

What is string concatenation?

A

It is the process of joining together two or more strings and containing it in a variable.

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 add two number values together and it can concatenate two 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

A boolean data type is returned, either true or false.

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 addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result to the variable. (Example: motto = motto + “ is the GOAT”)

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 and organize a model of something. To create subdivision of an object.

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

What are object properties?

A

Properties tell us about the object like details. They are 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

Objects are the properties and values within the curly braces and it is stored in a variable. So, it is a set of key-value pairs within curly braces being assigned to a variable. Properties are separated by colons and split by commas.

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

By using the delete keyword followed by the object name and property name separated by a dot.

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 either the dot notation or square brackets enclosing a set of quotation marks surrounding the 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

To store a list of similar data.

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

Describe array literal notation.

A

A set of values encased in square brackets separated by commas, assigned to a ‘var’ keyword and the variable name.

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 set ordered, they are indexed numerically, there is a constant count of the values in it.

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

By [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

It is the length or number of values 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

name of the object.length subtracted by 1.

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

What is a function in JavaScript?

A

It is a set of instructions(code) that is reusable.

31
Q

Describe the parts of a function definition.

A

function keyword, name of the function, parameter list, opening and closing curly braces for the function code block, and a return.

32
Q

Describe the parts of a function call.

A

the name of the function with its parameters.

33
Q

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

A

a call has just the function name with a set of (), a definition has the keyword, name, (parameters), and a function code block.

34
Q

What is the difference between a parameter and an argument?

A

parameters are placeholders and arguments are actually values.

35
Q

Why are function parameters useful?

A

to provide values to the function in order to get a new result.

36
Q

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

A

it first returns the output of a function and then it stops the code from running.

37
Q

Why do we log things to the console?

A

to verify output and see change over time (debugging)

38
Q

What is a method?

A

a function stored in a property.

39
Q

How is a method different from any other function?

A

methods are attached to objects. need to specific which object is it being pulled from.

40
Q

How do you remove the last element from an array?

A

.pop();

41
Q

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

A

.floor();

42
Q

How do you generate a random number?

A

Math.random() method

43
Q

How do you delete an element from an array?

A

.splice( , );

44
Q

How do you append an element to an array?

A

.push();

45
Q

How do you break a string up into an array?

A

.split();

46
Q

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

A

No, console.log it to the console or check in the console itself.

47
Q

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

A

There are 20 ~ 30.

48
Q

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

A

Not always, for example the pop method removes an element of an array

49
Q

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

A

There are about 35.

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

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

52
Q

What data type do comparison expressions evaluate to?

A

Boolean

53
Q

What is the purpose of an if statement?

A

It evaluates or checks a condition is true or false. (boolean) and to see if it should run the code block.

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

An if statement, then parentheses around the condition, opening curly brace, conditional code block.

56
Q

What are the three logical operators?

A

Logical and operator ( &&), logical or operator (| |), logical not operator (!)

57
Q

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

A

logical operators “and” or “or”

58
Q

What is the purpose of a loop?

A

to check a condition and if it comes back true then the code block will run. If not, it will continue to run until it does get a false result. A way of repeating action for as long as we need.

59
Q

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

A

It is the mechanism to signal a stop in a loop.

60
Q

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

A

it a run through of a condition to check the boolean value. One execution of the loop.

61
Q

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

A

first and before the code block executes

62
Q

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

A

when a variable is declared, when the loop first begins.

63
Q

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

A

before the code block executes and before each interation

64
Q

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

A

after the code block runs and at the end of the condition is met and true.

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 keyword brake

66
Q

What does the ++ increment operator do?

A

it increases the integer after each iteration by one

67
Q

How do you iterate through the keys of an object?

A

for … in loops

68
Q

What is the event.target?

A

the element where the event occured or dispatched from

69
Q

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

A

hides it from the user (not visible)

70
Q

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

A

it takes a string which is a CSS selector and returns a boolean value if true or not

71
Q

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

A

element.getAttribute(‘class name’)

72
Q

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

A

when declaring a variable, changing a variable, running through a loop, conditional and should be done after every step

73
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

would have to include a addEventListener for each tab and a callback function for each as well

74
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

would have to include a addEventListener for each tab and a callback function for each as well