JavaScript Flashcards

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
Q

Describe array literal notation.

A

var arrayName = [‘string’, value, …, ‘string’];

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 use index numbers for the key for each value.

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

Zero

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

arrayName.length

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

arrayName.length - 1

30
Q

What is a function in JavaScript?

A

Written code to be used throughout the program.

31
Q

Describe the parts of a function |definition|.

A

function functionName (parameters) {
code block
return;}

32
Q

Describe the parts of a function |call|.

A

functionName (argument);

33
Q

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

A

Defining has the |function| keyword

34
Q

What is the difference between a |parameter| and an |argument|?

A

Parameters are placeholders, arguments are the actual values to be passed through the function.

35
Q

Why are function |parameters| useful?

A

They allow the function to have any value.

36
Q

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

A

Causes the function to produce a value, prevents anymore code in the function code block from being run

37
Q

Why do we log things to the console?

A

To check if our output is correct and to see the data

38
Q

What is a method?

A

A function which is a property of an object

39
Q

How is a method different from any other function?

A

Methods are already defined / associated with objects.

40
Q

How do you remove the last element from an array?

A

arrayName.pop()

41
Q

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

A

Math.floor()

42
Q

How do you generate a random number?

A

Math.random()

43
Q

How do you delete an element from an array?

A

splice() -> splice (start, delete count)

44
Q

How do you append an element to an array?

A

push() - to the end of array
unshift() - to the front of array

45
Q

How do you break a string up into an array?

A

split(), pass argument to divide

46
Q

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

A

No the string stays the same, the output is different. With console.log

47
Q

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

A

Roughly 50

48
Q

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

A

Not every situation

49
Q

Roughly how may array methods are there according to MDN?

A

Roughly 40

50
Q

Give 6 examples of comparison operators?

A

==, !=, ===, !==, >, >=, <, <=

51
Q

What data type do comparison expressions evaluate to?

A

Booleans: true / false

52
Q

Is |else| required in order to use an |if| statement?

A

No

53
Q

Describe the syntax (structure) of an |if| statement?

A

if (condition) {code block}

54
Q

What is the purpose of a loop?

A

To run code multiple times on it’s own

55
Q

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

A

To tell the code to continue running or to stop

56
Q

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

A

The number of times the loop has run

57
Q

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

A

Before executing the statement

58
Q

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

A

Before the first loop starts

59
Q

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

A

In every iteration of the loop

60
Q

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

A

After the code block is run

61
Q

Besides a |return| statement, which exits its entire function block, which keyword exits a loop before it’s “condition” expression evaluates to |false|?

A

Break

62
Q

What does the |++| increment operator do?

A

Adds 1 to the counter

63
Q

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

A

focus

64
Q

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

A

blur

65
Q

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

A

input

66
Q

What event is fired when a user clicks the |”submit”| button within a |<form>|?

A

submit

67
Q

What does the |event.preventDefault()| method do?

A

Blocks an event from doing the “default”

68
Q

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

A

Automatically reloading the page with values stored in the URL.

69
Q

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

A

Elements property

70
Q

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

A

objectName.elements.elementName.value