JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store/see data that came together from the past & preserve data to use in the future

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 using let, const or 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

By using the assignment operator to give it value

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
Underscore
$
numbers (but it cannot be the first character)

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

Capitalized and lowercase letters mean different things

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 store a series of 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 perform math

To represent numeric values

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 make decisions

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

To make it hold/contain a value

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

By assigning 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 is intentional absence/emptiness

Undefined means there is no value assigned

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 make it easy to know which value the console is printing

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

Give five examples of JavaScript primitives.

A
Boolean
Null
Number
String
Undefined 

(and BigInt and Symbol)

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/number

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

What is string concatenation?

A

To join/append 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

To add numbers or to concatenate strings

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 (x === x, 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 the value on the right side of the operator to the variable and assigns the result back 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

To group together a set of properties and methods

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

What are object properties?

A

Chunk of data attached to objects

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

Describe object literal notation

A

var variableName = {
key : value,
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

With the delete operator

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

By using 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

For 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
arrayname[‘value’, ‘value’];
26
How are arrays different from "plain" objects?
There is an order They are numerically indexed It keeps a count of the number of values in it
27
What number represents the first index of an array?
0
28
What is the length property of an array?
It’s a property that returns the number of values in that array
29
How do you calculate the last index of an array?
arrayName.length - 1
30
What is a function in JavaScript?
Reusable block of code
31
Describe the parts of a function definition.
``` function optName(parameters) { block of code to run optional return keyword }; ```
32
Describe the parts of a function call:
functionName( );
33
When comparing them side-by-side, what are the differences between: a function call vs a function definition?
- No function keyword | - No curly braces and code block
34
What is the difference between a parameter and an argument?
Parameter is a placeholder name Argument is the value that actually gets passed
35
Why are function parameters useful?
They give us an idea of what kind of value were looking to put in the argument
36
What two effects does a return statement have on the behavior of a function?
1. Produces a value | 2. Ends the code block from running
37
Why do we log things to the console?
- To see change over time | - As a debugging mechanism
38
What is a method?
Function stored in a property | function that is the property of an object
39
How is a method different from any other function?
They are attached to objects (so you have to specify the object name)
40
How do you remove the last element from an array?
.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(index, how many items to remove)
44
How do you append (add to end) an element to an array?
.push()
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?
No (strings are immutable) | console.log()
47
Is the return value of a function or method useful in every situation?
No because sometimes you're interested in simply what the function/method does and not its return value
48
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
49
Give 6 examples of comparison operators
``` == === != !== < ><= >= ```
50
What data type do comparison expressions evaluate to?
Boolean
51
What is the purpose of an if statement?
Make a decision on which code block to run depending on the Boolean result
52
Is else required in order to use an if statement?
No – you don’t always need an alternative
53
Describe the syntax (structure) of an if statement.
``` if (condition) { statement1; } else { statement2; } ```
54
What are the three logical operators?
&& (and) || (or) ! (not)
55
How do you compare two different expressions in the same condition?
By using logical operators && or ||
56
What is the purpose of a loop?
To keep executing a code as long as a condition runs true
57
What is the purpose of a condition expression in a loop?
To let the function know when to end
58
What does "iteration" mean in the context of loops?
One execution of code block
59
When does the condition expression of a while loop get evaluated?
In the beginning before the code block executes
60
When does the initialization expression of a for loop get evaluated?
In the beginning before anything
61
When does the condition expression of a for loop get evaluated?
Before each iteration
62
When does the final expression of a for loop get evaluated?
After the code block is executed
63
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
64
What does the ++ increment operator do?
adds 1 to value
65
How do you iterate through the keys of an object?
for...in loop
66
What must the return value of myFunction be if the following expression is possible? myFunction()();
A function! | myFunction is being called and the return is being called immediately
67
What does this code do? const wrap = value => () => value;
Defines a function that defines the value and defines another function that returns that value
68
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
Defined
69
What allows JavaScript functions to "remember" values from their surroundings?
Closures
70
What does fetch() return?
A Promise If you get back a promise what do you do with it? You can call .then OR .catch on it
71
What is the default request method used by fetch()?
GET
72
How do you specify the request method (GET, POST, etc.) when calling fetch?
fetch('string of resource', { method: 'GET' })