JavaScript Flashcards

(110 cards)

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
Describe array literal notation.
``` var ___ = [ ]; the curly braces is the literal part ```
26
How are arrays different from "plain" objects?
arrays have an index automatically instead of a key, it also has a length property.
27
What number represents the first index of an array?
[0]
28
What is the length property of an array?
it stores the knowledge of how many values are in it.
29
How do you calculate the last index of an array?
length - 1 is how you calculate the last index of an array.
30
What is a function in JavaScript?
A function is a reusable part of code.
31
Describe the parts of a function definition.
Function has a keyword, optional name of the function. () that hold optional parameter list {code block} return statement
32
Describe the parts of a function call.
A function name followed by a list of parameters
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition features a keyword and a codeblock. A call has the arguments.
34
What is the difference between a parameter and an argument?
Parameter is an unknown placeholder type that's holding a spot for an eventual there (the argument).
35
Why are function parameters useful?
parameters allow us to leave a spot open for a value and call and get different results. You create adaptive behavior
36
What two effects does a return statement have on the behavior of a function?
Returns a value and ends the function
37
Why do we log things to the console?
console log is for debugging, it's only for developers. When you have an issue you should log all your values.
38
What is a method?
a method is a function that is a property of an object.
39
How is a method different from any other function?
Methods are functions that are part of objects. Other then that methods and functions are interchangeable (in javascript)
40
How do you remove the last element from an array?
The pop method.
41
How do you round a number down to the nearest integer?
Call the floor method
42
How do you generate a random number?
The random method of the math object
43
How do you delete an element from an array?
splice method
44
How do you append an element to an array?
push (append means add to the end)
45
How do you break a string up into an array?
split
46
Do string methods change the original string? How would you check if you weren't sure?
console log the string if you aren't sure. String methods destroy the string and make a new one because they are immutable
47
Roughly how many string methods are there according to the MDN Web docs?
45-50, there are a lot
48
Is the return value of a function or method useful in every situation?
not everytime do you need the return of something.
49
Roughly how many array methods are there according to the MDN Web docs?
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
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
mdn
51
Give 6 examples of comparison operators.
===, !==, >, =, <=
52
What data type do comparison expressions evaluate too?
values, variables, whole expressions
53
What is the purpose of an if statement?
If statements evaluate a condition and allow different code to run depending on the results
54
Is else required in order to use an if statement?
No, If there's only an if statement and it's condition isn't met it simply skips it.
55
Describe the syntax (structure) of an if statement.
if(condition) {code to execute}
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
(condition logical operator condition)
58
What is the purpose of a loop?
It lets you repeat something without you having to do it yourself.
59
What is the purpose of a condition expression in a loop?
A condition is an expression in order to stop a loop.
60
What does "iteration" mean in the context of loops?
Iteration in the context of loops means iterating something with the purpose of eventually getting the loop to end
61
When does the condition expression of a while loop get evaluated?
Before each iteration of the loop
62
When does the initialization expression of a for loop get evaluated?
Initialization only happens at the start one time
63
When does the condition expression of a for loop get evaluated?
Before each iteration of the loop, after the first initialization.
64
When does the final expression of a for loop get evaluated?
final expression happens after the code block runs and before the condition runs.
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break, not super common but it does exist.
66
What does the ++ increment operator do?
++ substitutes the value of the variable and increments the value of the variable
67
How do you iterate through the keys of an object?
By using a for in loop
68
Why do we log things to the console?
To check, debug, or verify if what we are trying to do is correct
69
What is a "model"?
A representation of a structure or system that you want to follow or imitate.
70
Which "document" is being referred to in the phrase Document Object Model?
The doctype declaration
71
What is the word "object" referring to in the phrase Document Object Model?
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
What is a DOM Tree?
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
Give two examples of document methods that retrieve a single element from the DOM.
getElementById() and querySelector()
74
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll()
75
Why might you want to assign the return value of a DOM query to a variable?
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
What console method allows you to inspect the properties of a DOM element object?
console.dir();
77
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.
78
11) What does document.querySelector() take as its argument and what does it return?
The return is the first element of the document that matches that selector It takes a string as the argument
79
What does document.querySelectorAll() take as | its argument and what does it return?
It takes a string and returns a node list
80
Why do we log things to the console?
To debug, check, and verify that everything is working.
81
What is the purpose of events and event handling?
To update and give a feeling of interactivity with the user
82
Are all possible parameters required to use a JavaScript method or function?
no
83
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addeventlistener methods
84
What is a callback function?
A function passed into another function as an argument. In order to complete an action. Being passed around like a value
85
What object is passed into an event listener callback when the event fires?
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
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
You can look it up on mdn. It is a property. of event. It says where the event occurred
87
What is the difference between these two snippets of code?
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
What is the className property of element objects?
It gets and sets the class value of a specified element
89
How do you update the CSS class attribute of an element using JavaScript?
first query for the element into a variable | get the value and use the classname method
90
What is the textContent property of element objects?
It represents the text content of the element node and it's descendants
91
How do you update the text within an element using JavaScript?
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
Is the event parameter of an event listener callback always useful?
Not always useful. It is pretty useful though
93
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
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
Why is storing information about a program in variables better than only storing it in the DOM
Storing things in variables is easier for javascript to work with. It's extremely inefficient.
95
What event is fired when a user places their cursor in a form control?
focus event
96
What event is fired when a user's cursor leaves a form control?
blur event
97
What event is fired as a user changes the value of a form control?
input event
98
What event is fired when a user clicks the "submit" button within a ?
submit event
99
What does the event.preventDefault() method do? What does submitting a form without event.preventDefault() do?
It prevents the page from resetting. It prevents the default behavior. It refreshes. The default behavior happens.
100
What property of a form element object contains all of the form's controls.
The Name property
101
What property of a form control object gets and sets its value?
The value property, allows you to access the value stored
102
What is one risk of writing a lot of code without checking to see if it works so far?
You can waste a lot of time and make debugging difficult
103
What is an advantage of having your console open when writing a JavaScript program?
Just to see progress and see if what's coming out is think is coming out
104
Does the document.createElement() method insert a new element into the page?
No, it is not part of the DOM tree until you use the appendChild method
105
How do you add an element as a child to another element?
The appendChild() method
106
What do you pass as the arguments to the element.setAttribute() method?
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
What steps do you need to take in order to insert a new element into the page?
assign a variable and use the createElement() method, then at some point appendChild() it to a queried variable
108
What is the textContent property of an element object for?
The textContent property allows you to either get the element's text content, or set the text content
109
Name two ways to set the class attribute of a DOM element.
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
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
We can reuse the tree/foundation as many times as we want. If something is wrong it's very easy to test.