JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To help store data for the computer to remember

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

How do you declare a variable?

A

Creating the variable (keyword) and giving it a 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

You use the = 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, Dollar Signs, Numbers, Underscore

Can’t start with number, use periods, or dashes

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 match or else they are two different variables

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

A way to hold a sequence of characters

Used to represent characters

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 store number and used for math

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 let the user know whether something is true or false

Helps the user make a choice based on the output

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 an 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

You write the variable and use the assignment operator with a new value

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 means intentional absence of a value (Like a placeholder for you to put in value later) while undefined means no value was assigned to a variable

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

Makes it much easier for you see which variable is being logged and in what order

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, Null, Undefined, Boolean

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

Number

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

What is string concatenation?

A

The process of joining a value with another string and resulting in 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

To add two values together or concatenate string together

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

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 the value of the right operand to a variable and assigns the result to 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

They group together a set of variables and functions to create a model of something you would see in the real world

Ex. An organized bubble where you can get bits of information from of the object that are related to one another

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

What are object properties?

A

The key and values within the object (The data within the object)

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

Describe object literal notation.

A

The object properties (Key and values)

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

Using the delete operator followed by object name and key

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

Dot notation and 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

For creating a list of values that are related to one another with order may or may not mattering

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

Describe array literal notation.

A

A variable and name followed by = with square brackets with content separated by comma’s

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 a length property, arrays call a method to add data while objects assign it, arrays have an order while objects don’t

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

True count of items within the array

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

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 chunk of code that returns data for you to reuse

31
Q

Describe the parts of a function definition.

A

Function keyword, optional name, comma-separated list of zero or more parameters that are surrounded by parentheses, an opening curly brace to open the function’s code block, an optional return statement, and a closing curly brace to end the function’s code block

32
Q

Describe the parts of a function call.

A

Starts with the functions name followed by comma-separated arguments that are surrounded by parentheses

33
Q

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

A

Calling a function runs the code while defining a function creates it

Function call has no code block while function definition does

Function keyword for defining it but no function keyword when calling it

34
Q

What is the difference between a parameter and an argument?

A

A parameter is a placeholder for the function while an argument is a value being passed when calling the function

35
Q

Why are function parameters useful?

A

They act as a placeholder which you can pass an argument into

36
Q

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

A

It causes the function to return a value you can use in the program and prevents any more code in the functions block from being run

37
Q

Give 6 examples of comparison operators.

A

Greater than, less than, equal to, not equal to, strictly equal, strictly not equal

38
Q

What data type do comparison expressions evaluate to?

A

A boolean (True or False)

39
Q

What is the purpose of an if statement?

A

It lets the computer make a choice

40
Q

Is else required in order to use an if statement?

A

No

41
Q

Describe the syntax (structure) of an if statement.

A

Keyword if, parentheses, condition, opening curly brace, code block, closing curly brace

42
Q

What are the three logical operators?

A

And, or, not

43
Q

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

A

&& or ||

44
Q

Why do we log things to the console?

A

To check our progress and make sure our code is working

For debugging

45
Q

What is a method?

A

A function that is a property of an object

46
Q

How is a method different from any other function?

A

A method is a function within an object while a function is a code snippet that can be called by other code or by itself

47
Q

How do you remove the last element from an array?

A

.pop()

48
Q

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

A

Math.floor()

49
Q

How do you generate a random number?

A

Math.random()

50
Q

How do you delete an element from an array?

A

.splice()

51
Q

How do you append an element to an array?

A

.push()

52
Q

How do you break a string up into an array?

A

.split()

53
Q

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

A

No and you can check by using the console log

54
Q

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

A

No

55
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

56
Q

What is the purpose of a loop?

A

To perform a repeated code block until a specified condition is met

57
Q

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

A

An expression that needs to be evaluated to see if the loop will stop

58
Q

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

A

The number of times the loops runs

59
Q

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

A

Before the loop runs (Each iteration)

60
Q

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

A

Before each loop iteration

61
Q

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

A

After the initialization

Before the loop begins

62
Q

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

A

At the end of each loop iteration

and before the conditional

63
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

64
Q

What does the ++ increment operator do?

A

It increases the variable it is used on by 1

65
Q

How do you iterate through the keys of an object?

A

for in

66
Q

What is JSON?

A

A format used to save data in a string to use for later

A text based format

67
Q

What are serialization and deserialization?

A

Serialization is the process of changing an object in the memory into a stream of bytes to either store or send over the network

Deserialization is the opposite, changing a stream of bytes back into an object in the memory

68
Q

Why are serialization and deserialization useful?

A

Serialization is useful for converting data into bytes for storing data and sending over and vice versa

Deserialization is useful for breaking it down

69
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

70
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse()

71
Q

How do you store data in localStorage?

A

localStorage.setItem()

Takes key and value as arguments

72
Q

How do you retrieve data from localStorage?

A

localStorage.getItem()

Takes the key name as arguments

73
Q

What data type can localStorage save in the browser?

A

String data

74
Q

When does the ‘beforeunload’ event fire on the window object?

A

When the document and its resources are about to be closed