JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store data and use it 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

by putting var ____ < 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

use the equal operator it represents the word “assignment”

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

lowercase, numbers, dollar sign, underscore. No dash(-) or (.), also do not start with a number. Start with either a letter, dollar sign, or 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

score and Score are considered different variables (DO NOT DO THIS)

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 write characters and words

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 give data

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

It is an on off switch that can be used to determine whether something should run in a script

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 assignment

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 var keyword isn’t necessary but you simply reassign it later in the document.

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 an intentional way of saying nothing, undefined is the way the computer says nothing. Every null value you see is purposeful.

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 provide clarity for other people and for you in the future.

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

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

numeric data type, some sort of 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 taking two strings together and gluing them to make a new string

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

arithmetic operations, string operations (concatenating)

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 data types

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

it’s shorthand
motto+= ‘is the goat’;
motto=motto + ‘is the goat’;
they are the same, the way you read the second line is what the first one is doing

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

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

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

Describe object literal notation.

A

object literals itself is the 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

use the delete operator object.property

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

bracket notation and dot notation
anything that follows the dot notation is a string
bracket notation lets you check for an expression when accessing a property

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

What are arrays used for?

A

a list or a set of values related to each other. Especially useful if you aren’t sure how big the list will be. Also the keys are indexed automatically with a number.

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

Describe array literal notation.

A
var \_\_\_ = [ ];  
the curly braces is the literal part
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 an index automatically instead of a key, it also has 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

[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 stores the knowledge of how many values are in it.

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

length - 1 is how you calculate the last index of an array.

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 function is a reusable part of code.

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

Function has a keyword, optional name of the function. () that hold optional parameter list
{code block} return statement

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 name followed by a list of parameters

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

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

A

function definition features a keyword and a codeblock. A call has the arguments.

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

What is the difference between a parameter and an argument?

A

Parameter is an unknown placeholder type that’s holding a spot for an eventual there (the argument).

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

Why are function parameters useful?

A

parameters allow us to leave a spot open for a value and call and get different results. You create adaptive behavior

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

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

A

Returns a value and ends the function

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

Why do we log things to the console?

A

console log is for debugging, it’s only for developers. When you have an issue you should log all your values.

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

What is a method?

A

a method is a function that is a property of an object.

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

How is a method different from any other function?

A

Methods are functions that are part of objects. Other then that methods and functions are interchangeable (in javascript)

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

How do you remove the last element from an array?

A

The pop method.

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

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

A

Call the floor method

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

How do you generate a random number?

A

The random method of the math object

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

How do you delete an element from an array?

A

splice method

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

How do you append an element to an array?

A

push (append means add to the end)

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

console log the string if you aren’t sure. String methods destroy the string and make a new one because they are immutable

47
Q

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

A

45-50, there are a lot

48
Q

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

A

not everytime do you need the return of something.

49
Q

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

A

around 40-50, a lot. Strings and arrays are the most common types of data we need to change so there’s a loooot of methods.

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 too?

A

values, variables, whole expressions

53
Q

What is the purpose of an if statement?

A

If statements evaluate a condition and allow different code to run depending on the results

54
Q

Is else required in order to use an if statement?

A

No, If there’s only an if statement and it’s condition isn’t met it simply skips it.

55
Q

Describe the syntax (structure) of an if statement.

A

if(condition) {code to execute}

56
Q

What are the three logical operators?

A

&&, ||, !

57
Q

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

A

(condition logical operator condition)

58
Q

What is the purpose of a loop?

A

It lets you repeat something without you having to do it yourself.

59
Q

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

A

A condition is an expression in order to stop a loop.

60
Q

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

A

Iteration in the context of loops means iterating something with the purpose of eventually getting the loop to end

61
Q

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

A

Before each iteration of the loop

62
Q

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

A

Initialization only happens at the start one time

63
Q

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

A

Before each iteration of the loop, after the first initialization.

64
Q

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

A

final expression happens after the code block runs and before the condition runs.

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, not super common but it does exist.

66
Q

What does the ++ increment operator do?

A

++ substitutes the value of the variable and increments the value of the variable

67
Q

How do you iterate through the keys of an object?

A

By using a for in loop

68
Q

Why do we log things to the console?

A

To check, debug, or verify if what we are trying to do is correct

69
Q

What is a “model”?

A

A representation of a structure or system that you want to follow or imitate.

70
Q

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

A

The doctype declaration

71
Q

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

A

The DOM is a javascript object that is modeling an html document. The DOM IS NOT the html document. It builds itself by observing the html document.

It refers to the document object. You always have to access individual elements via the document object.

72
Q

What is a DOM Tree?

A

The DOM tree is a model of a web page. Parent element and all of it’s child elements, it is the makeup of the element and all of it’s contents.

73
Q

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

A

getElementById() and querySelector()

74
Q

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

A

querySelectorAll()

75
Q

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

A

So that way you can just store the location of the elements. This saves the browser looking through the DOM tree. Which is known as caching the selection.

76
Q

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

A

console.dir();

77
Q

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

A

The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.

78
Q

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

A

The return is the first element of the document that matches that selector
It takes a string as the argument

79
Q

What does document.querySelectorAll() take as

its argument and what does it return?

A

It takes a string and returns a node list

80
Q

Why do we log things to the console?

A

To debug, check, and verify that everything is working.

81
Q

What is the purpose of events and event handling?

A

To update and give a feeling of interactivity with the user

82
Q

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

A

no

83
Q

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

A

addeventlistener methods

84
Q

What is a callback function?

A

A function passed into another function as an argument. In order to complete an action. Being passed around like a value

85
Q

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

A

It includes an object with all the data that the event occurs. With every event that occurs you are given the object of every property javascript thinks the event object wants you to know. An object with all data for whatever event occurred.

86
Q

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

A

You can look it up on mdn. It is a property. of event. It says where the event occurred

87
Q

What is the difference between these two snippets of code?

A

The first one is going to work properly, the second one has a return. eventlisteners never really have returns. so element.addEventListener(‘click’, handleClick)
YOU WILL ALWAYS PUT a function definition, never do a function call

88
Q

What is the className property of element objects?

A

It gets and sets the class value of a specified element

89
Q

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

A

first query for the element into a variable

get the value and use the classname method

90
Q

What is the textContent property of element objects?

A

It represents the text content of the element node and it’s descendants

91
Q

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

A

Select the element you want with a query selector. And then get your new value and use the text content property on the new variable you queried

92
Q

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

A

Not always useful. It is pretty useful though

93
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

It would be way more complicated. Storing information on the dom without variables is a horrible scenario. Javascript functionality should be reliant on javascript variables.

94
Q

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

A

Storing things in variables is easier for javascript to work with. It’s extremely inefficient.

95
Q

What event is fired when a user places their cursor in a form control?

A

focus event

96
Q

What event is fired when a user’s cursor leaves a form control?

A

blur event

97
Q

What event is fired as a user changes the value of a form control?

A

input event

98
Q

What event is fired when a user clicks the “submit” button within a ?

A

submit event

99
Q

What does the event.preventDefault() method do? What does submitting a form without event.preventDefault() do?

A

It prevents the page from resetting. It prevents the default behavior.
It refreshes. The default behavior happens.

100
Q

What property of a form element object contains all of the form’s controls.

A

The Name property

101
Q

What property of a form control object gets and sets its value?

A

The value property, allows you to access the value stored

102
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

You can waste a lot of time and make debugging difficult

103
Q

What is an advantage of having your console open when writing a JavaScript program?

A

Just to see progress and see if what’s coming out is think is coming out

104
Q

Does the document.createElement() method insert a new element into the page?

A

No, it is not part of the DOM tree until you use the appendChild method

105
Q

How do you add an element as a child to another element?

A

The appendChild() method

106
Q

What do you pass as the arguments to the element.setAttribute() method?

A

You usually set the name of the attribute you want (like class), and then the value as the second argument.

b.setAttribute(‘class’, ‘column-third’)

107
Q

What steps do you need to take in order to insert a new element into the page?

A

assign a variable and use the createElement() method, then at some point appendChild() it to a queried variable

108
Q

What is the textContent property of an element object for?

A

The textContent property allows you to either get the element’s text content, or set the text content

109
Q

Name two ways to set the class attribute of a DOM element.

A

You can set it with setAttribute. I’m unsure of the second way, you can use getAttribute to get the current value as well as removeAttribute. Assign a string to the classname property of the element object.

110
Q

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

We can reuse the tree/foundation as many times as we want. If something is wrong it’s very easy to test.