JavaScript Flashcards

1
Q

What is the purpose of variables?

A

They are used to store data to utilize later on.

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 the “var” keyword and the 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 and the variable value.

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, dollar sign, underscore, numbers (cannot start with one)

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 have to match exactly with correct capitalization.

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

They hold text, letters and other 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

For counting or calculating 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
  • To determine which part of a script should run.

- Logic with binary states.

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

Assignment operator, used to assign a 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

The name of the variable with the new 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
  • Null is a nonexistent or invalid object or address
  • Null has to be assigned.
  • Undefined are for 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

Labels in the console are good for knowing where the value stems from.

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.

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 number.

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

What is string concatenation?

A

Combining string values.

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
  • Adding together numbers, strings, and variables.
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

Boolean

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

Adds the value and 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
  • Grouping together a set of variables and functions to create a model.
  • A box of data related to each other grouped together.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are object properties?

A

Properties are variables that tell us about the object.

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

Describe object literal notation.

A

Curly braces and its contents.

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.

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

Lists or 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

Square brackets with each value separated by a comma.

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 have index numbers, an order, and square brackets.

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

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

A true count of the amount of items within 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

One less than the length of the array.

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

Why do we log things to the console?

A

It’s a debugging tool used to check errors.

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

What is a method?

A

Methods are functions which is a property of an object.

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

How is a method different from any other function?

A

Property of an object.

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

How do you remove the last element from an array?

A

pop method

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

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

A

floor method

35
Q

How do you generate a random number?

A

random method

36
Q

How do you delete an element from an array?

A

splice method

37
Q

How do you append an element to an array?

A

push method

38
Q

How do you break a string up into an array?

A

split method

39
Q

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

A
  • They do not change the original string.

- To check just log it into a console.

40
Q

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

A

Around 30 string methods.

41
Q

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

A

No.

42
Q

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

A

Around 25 array methods.

43
Q

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

A

MDN

44
Q

Give 6 examples of comparison operators.

A

===, !=, less than, greater than, less than or equal to, greater than or equal to, &&

45
Q

What data type do comparison expressions evaluate to?

A

Boolean

46
Q

What is the purpose of an if statement?

A

Evaluates or checks a condition to see if its true, if it is then the code block executes.

47
Q

Is else required in order to use an if statement?

A

No, if you don’t need a fallback.

48
Q

Describe the syntax (structure) of an if statement.

A

if keyword - condition - code block

49
Q

What are the three logical operators?

A

and operator, or operator, logical not operator

50
Q

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

A

logical operator: and, or

51
Q

What is the purpose of a loop?

A

Repeating an action some number of times, under a certain condition.

52
Q

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

A

To see if the loop will execute or not. If it’s true, then it will, if it’s false then it will terminate.

53
Q

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

A

One repetition for the code block.

54
Q

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

A

Evaluated before the code block runs.

55
Q

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

A

It happens first and only once.

56
Q

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

A

After the initialization, and before each iteration.

57
Q

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

A

At the end of each iteration, before the condition.

58
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.

59
Q

What does the ++ increment operator do?

A

Adds 1 and assigns it to a variable.

60
Q

How do you iterate through the keys of an object?

A

For…in loop.

61
Q

What is a “model”?

A

A model is representation of something.

62
Q

Which “document” is being referred to in the phrase Document Object Model?

A

The HTML page.

63
Q

What is the word “object” referring to in the phrase Document Object Model?

A

The different parts of a page.

64
Q

What is a DOM Tree?

A

An element and all of its children.

65
Q

Give two examples of document methods that retrieve a single element from the DOM.

A

getElementByID() and querySelector().

*use querySelector for everything

66
Q

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

querySelectorAll()

67
Q

Why might you want to assign the return value of a DOM query to a variable?

A

If you need to reuse the element more than once it is much easier to access.

68
Q

What console method allows you to inspect the properties of a DOM element object?

A

console.dir()

69
Q

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

HTML and CSS needs to be ran and loaded before the script can run.

70
Q

What does document.querySelector() take as its argument and what does it return?

A

Takes a string of a CSS selector.

71
Q

What does document.querySelectorAll() take as its argument and what does it return?

A

Also takes a string of a CSS selector.

72
Q

What is the purpose of events and event handling?

A

Events are used to trigger a particular function.

Event handling are the steps involved in getting it to trigger.

73
Q

Are all possible parameters required to use a JavaScript method or function?

A

No.

74
Q

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

addEventListener()

75
Q

What is a callback function?

A

A function passed into another function as an argument.

76
Q

What object is passed into an event listener callback when the event fires?

A

The event object.

77
Q

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

The target property of the event object into which the event was dispatched.

78
Q

What is the className property of element objects?

A

It gets and sets the value of the class attribute of the specified element.

79
Q

How do you update the CSS class attribute of an element using JavaScript?

A

The className property with a string value with the name of the class.

80
Q

What is the textContent property of element objects?

A

Represents the text content of the node and its descendants.

81
Q

How do you update the text within an element using JavaScript?

A

The textContent property and the value of a string.

82
Q

Is the event parameter of an event listener callback always useful?

A

No.

83
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

Variables allow you to make adjustments easily.

They are more dynamic.