JavaScript Flashcards

(70 cards)

1
Q

What is the purpose of variables?

A

To temporarily store data needed to run scripts

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

How do you “declare” a variable?

A

Using the keyword var
var variableName = variableValue

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

= (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

Letters, $, _

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

Uppercases matter: tom is different than Tom

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 assign any text value

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

Used for counting / calculating

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

Gives true or false, helps determine which script to run

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

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

variableName = newValue

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 represents an invalid or nonexistent object, undefined represents no 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

To help with debugging and know which functions you are working with

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

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 strings and numbers together for a longer 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

Concatenation and adding values

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?

A

Booleans

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

What does the |+=| “plus-equals” serve in JavaScript?

A

Adds value of the right side to a variable and assigns result to said variable

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

What are objects used for?

A

To create a model of something recognizable from the real world by grouping together a 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

Variables that are part of the object

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

Describe object literal notation.

A

var objectName = {
key: value, };

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 objectName.propertyName;

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 pf a property?

A

dot notation or square brackets

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

What are arrays used for?

A

When you are working with a list or set of values related to each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
var arrayName = ['string', value, ..., 'string'];
26
How are arrays different from "plain" objects?
Arrays use index numbers for the key for each value.
27
What number represents the first index of an array?
Zero
28
What is the |length| property of an array?
arrayName.length
29
How do you calculate the last index of an array?
arrayName.length - 1
30
What is a function in JavaScript?
Written code to be used throughout the program.
31
Describe the parts of a function |definition|.
function functionName (parameters) { code block return;}
32
Describe the parts of a function |call|.
functionName (argument);
33
When comparing them side-by-side, what are the differences between a function |call| and a function |definition|?
Defining has the |function| keyword
34
What is the difference between a |parameter| and an |argument|?
Parameters are placeholders, arguments are the actual values to be passed through the function.
35
Why are function |parameters| useful?
They allow the function to have any value.
36
What two effects does a |return| statement have on the behavior of a function?
Causes the function to produce a value, prevents anymore code in the function code block from being run
37
Why do we log things to the console?
To check if our output is correct and to see the data
38
What is a method?
A function which is a property of an object
39
How is a method different from any other function?
Methods are already defined / associated with objects.
40
How do you remove the last element from an array?
arrayName.pop()
41
How do you round a number down to the nearest integer?
Math.floor()
42
How do you generate a random number?
Math.random()
43
How do you delete an element from an array?
splice() -> splice (start, delete count)
44
How do you append an element to an array?
push() - to the end of array unshift() - to the front of array
45
How do you break a string up into an array?
split(), pass argument to divide
46
Do string methods change the original string? How would you check if you weren't sure?
No the string stays the same, the output is different. With console.log
47
Roughly how many string methods are there according to the MDN docs?
Roughly 50
48
Is the return value of a function or method useful in every situation?
Not every situation
49
Roughly how may array methods are there according to MDN?
Roughly 40
50
Give 6 examples of comparison operators?
==, !=, ===, !==, >, >=, <, <=
51
What data type do comparison expressions evaluate to?
Booleans: true / false
52
Is |else| required in order to use an |if| statement?
No
53
Describe the syntax (structure) of an |if| statement?
if (condition) {code block}
54
What is the purpose of a loop?
To run code multiple times on it's own
55
What is the purpose of a "condition" expression in a loop?
To tell the code to continue running or to stop
56
What does "iteration" mean in the context of the loop?
The number of times the loop has run
57
When does the "condition" expression of a |while| loop get evaluated?
Before executing the statement
58
When does the "initialization" expression of a |for| loop get evaluated?
Before the first loop starts
59
When does the "condition" expression of a |for| loop get evaluated?
In every iteration of the loop
60
When does the "final" expression of a |for| loop get evaluated?
After the code block is run
61
Besides a |return| statement, which exits its entire function block, which keyword exits a loop before it's "condition" expression evaluates to |false|?
Break
62
What does the |++| increment operator do?
Adds 1 to the counter
63
What event is fired when a user places their cursor in a form control?
focus
64
What event is fired when a user's cursor leaves a form control?
blur
65
What event is fired when a user changes the value of a form control?
input
66
What event is fired when a user clicks the |"submit"| button within a |
|?
submit
67
What does the |event.preventDefault()| method do?
Blocks an event from doing the "default"
68
What does submitting a form without |event.preventDefault()| do?
Automatically reloading the page with values stored in the URL.
69
What property of a form element object contains all of the form's controls?
Elements property
70
What property of a form control objects gets and sets its value?
objectName.elements.elementName.value