JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store data

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 keyword “var”

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

var variable = something

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

letter, digits, underscore, dollar signs

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

they must be recalled exactly as they were saved

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

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

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

to register something as true or false

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 assigning a value to a variable name

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

What is the difference between null and undefined?

A

null is intentionally given a non-existing value, undefined unintentionally lacks a value

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

so that you have a better idea of what issues may have occurred when debugging

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

Give five examples of JavaScript primitives.

A

string, number, boolean, undefined, null

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

to update a variable

A

use variable followed by value… don’t need to use ‘var’ again

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

the combining of two or more strings

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 adds a value to another variable/value

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 a value to a variable and re-assigns 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

group together set of 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

a variable within an object

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

Describe object literal notation.

A

a saved variable followed by curly brace with key-value properties and methods (functions)

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

delete then 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

either dot or 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

storing a list of values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
var name = [skhf,fskdjhf,skdjfh]
26
How are arrays different from "plain" objects?
do not use colons, do not use curly braces, etc arrays are indexed, objects aren't
27
What number represents the first index of an array?
0
28
What is the length property of an array?
array.length... tells you how many items are listed
29
How do you calculate the last index of an array?
array.length - 1
30
What is a function in JavaScript?
a set of statements that perform a task or calculate a value based off their parameters, and code block
31
Describe the parts of a function definition.
parts of a function definition include function name, parameters/arguments, curly brace, optional return statement, and the code
32
Describe the parts of a function definition.
parts of a function definition include function name, parameters/arguments, curly brace, optional return statement, and the code
33
Describe the parts of a function call.
functionName(optional arguments)
34
When comparing them side-by-side, what are the differences between a function call and a function definition?
no function key word and no brackets in function call... definition does have it
35
What is the difference between a parameter and an argument?
parameter has no value while argument does
36
Why are function parameters useful?
to tell you what type of value to input into a function
37
What two effects does a return statement have on the behavior of a function?
stops the code from running any longer, causes function to produce a value we can use in our program
38
Why do we log things to the console?
so that we can see the output of our code and make sure things are functioning properly
39
What is a method?
a function which is a property of an object.... essentially a built in function
40
How is a method different from any other function?
property of an object while other functions are hanging in space
41
How do you remove the last element from an array?
.pop() method
42
How do you round a number down to the nearest integer?
Math.floor() method
43
How do you generate a random number?
Math.random() method
44
How do you delete an element from an array?
.splice(1,0) method
45
How do you append an element to an array?
.push() method
46
How do you break a string up into an array?
.split() method
47
Do string methods change the original string? How would you check if you weren't sure?
no, you assign the value of the string method response to a new variable and call the original string if you want to see it
48
Roughly how many string methods are there according to the MDN Web docs?
Around 50
49
roughly how many array methods are there according to the MDN web docs
40-50
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
51
is a return value useful in every situation
not necessarily, you might just pop something off an array and thats it
52
Give 6 examples of comparison operators.
< > <= >= != = ===etc
53
What data type do comparison expressions evaluate to?
booleans (true or false)
54
What is the purpose of an if statement?
if that condition is met, then run the following code
55
Is else required in order to use an if statement?
no
56
Describe the syntax (structure) of an if statement.
if keyword followed by parentheses, rule, curly brace, code
57
What are the three logical operators?
"and" "or", and "not"
58
How do you compare two different expressions in the same condition?
have both expressions in the same parenthesis
59
What is the purpose of a loop?
run repeated code under specific conditions
60
What is the purpose of a condition expression in a loop?
tells you requirements on if the loop should run and how long the loop should be run
61
What does "iteration" mean in the context of loops?
each "time" the code is executed
62
When does the condition expression of a while loop get evaluated?
beginning of each iteration
63
When does the initialization expression of a for loop get evaluated?
the start of the loop
64
When does the condition expression of a for loop get evaluated?
after initialization at first, then after every iteration
65
When does the final expression of a for loop get evaluated?
after the iteration
66
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break keyword
67
What does the ++ increment operator do?
increments by 1
68
How do you iterate through the keys of an object?
for-in loop
69
Why do we log things to the console?
so that we can see the output of our actions
70
What is a "model"?
recreation of something
71
Which "document" is being referred to in the phrase Document Object Model?
the html document
72
What is the word "object" referring to in the phrase Document Object Model?
every tree node... the separate parts of the html
73
What is a DOM Tree?
a layout of all html objects
74
Give two examples of document methods that retrieve a single element from the DOM.
document.getElementById() document.querySelector()
75
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.getElementsByClassName() document.querySelectorAll()
76
Why might you want to assign the return value of a DOM query to a variable?
so that you can call that variable and change another attribute about it.... or just to refer back to it
77
What console method allows you to inspect the properties of a DOM element object?
console.dir()
78
Why would a