JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store or remember information.

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

How do you declare a variable?

A
  • var
  • let
  • const
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

Using one equal sign.

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
  • Variable names must start with a letter, underscore, or dollar sign.
  • Variable names cannot contain spaces.
  • Variable names can only contain letters, numbers, underscores, and dollar signs.
  • Variable names are case-sensitive.
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

Variable names have to be specific. (firstname & firstName 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

Used to represent and manipulate 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 if a number?

A

Used to represent and manipulate numbers.

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

Used when determining which part of a script should run. (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

Assigns a value to a variable.

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 using the name of the variable and assigning it 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 a type of object that is intentionally given no value.
  • Undefined is when a variable is defined, but never given a value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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
13
Q

What is a string concatenation?

A

Joining strings together to create one new string.

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

What purpose(s) does the + plus operator serve in JavaScript?

A

To add numbers and concatenate strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
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
16
Q

What does the += “plus-equals” operator do?

A

It 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
17
Q

What are objects used for?

A

To group together a set of variables and functions to create a model of something you would recognize from the real world.

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

What are object properties?

A
  • Variables with values.

* Allow us to store information in an object literal.

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

Describe literal notation.

A
  • Assigning an object literal to a variable.

* Within the object, there are properties (variables) and methods (functions).

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

How do you remove a property from an object?

A
  • By using the delete keyword followed by the object name and property name
  • By using the delete operator.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are two ways to get or update the value of a property.

A
  • object.property-name = value - Dot Notation

* object[‘property-name’] = value - Bracket Notation

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

Why do we log things to the console?

A

To debug and see if the output is what you want it to be.

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

What is a method?

A

A function which is a property of an object.

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

How is a method different from any other function?

A

A method is associated/attached with an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do you remove the last element from an array?
Using the Array.prototype.pop() method.
26
How do you round a number down to the nearest integer.
Using the Math.floor() method.
27
How do you generate a random number?
Using the Math.random() method.
28
How do you delete an element from an array?
Using the Array.prototype.splice() method.
29
How do you append an element to an array?
Using the Array.prototype.push() method.
30
How do you break a string up into an array?
Using the String.prototype.split() method.
31
Do string methods change the original string? How would you check if you weren't sure?
They do not, they are immutable, and only reassign the variable. You would check by looking at the documentation or console log.
32
Roughly how many string methods are there according to the MDN Web Docs?
About 30 string methods.
33
Is the return value of a function or method useful in every situation?
No, you don't always need to use the return value.
34
Roughly how many array methods are there according to MDN Web Docs?
About 30 array methods.
35
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN.
36
What is the purpose of a loop?
• To run a certain block of code as fast as possible until something tells it to stop.
37
What is the purpose of a condition expression in a loop?
To tell the loop when to start and stop.
38
What does "iteration" mean in the context of loops?
Iteration means how many times the code in the loop runs.
39
When does the condition expression of a while loop get evaluated?
Before each pass through the loop.
40
When does the initialization expression of a for loop get evaluated?
Once, before the loop begins.
41
When does the condition statement of a for loop get evaluated?
Before each loop iteration.
42
When does the final expression of a for loop get evaluated?
At the end of each loop iteration.
43
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break.
44
What does the ++ increment operator do?
It increments a number up by one.
45
How do you iterate through the keys of an object?
By using a for...in loop.
46
Give 6 examples of comparison operators.
* > - (Greater Than) * < - (Less Than) * === - (Strictly Equal To) * == - (Equal To) * != - (Is Not Equal To) * !== - (Strictly Not Equal To)
47
What data type do comparison expressions evaluate to?
Boolean.
48
What is the purpose of an if statement?
• To make decisions in our code.
49
Is else required in order to use an if statement?
No.
50
Describe the syntax (structure) of an if statement.
* if Keyword * condition * code block
51
What are the three logical operators?
* && - (Logical And) * || - (Logical Or) * ! - (Logical Not)
52
How do you compare two different expressions in the same condition?
By using a logical operator.
53
What is a function in JavaScript?
A series of steps that are performed when they are called and passed a value.
54
Describe the parts of a function definition.
* The Function Keyword. * The name of the function (optional). * Parameters surrounded by parentheses. * The function's code block {}. * Return Statement (optional).
55
Describe the parts of a function call.
* Function Name. | * (Arguments).
56
When comparing them side-by-side, what are the differences between a function call and a function definition?
* The function definition holds all the code. | * The function call runs the code.
57
What is the difference between a parameter and an argument?
* A parameter is a placeholder. | * An argument is what is passed through the function when we call a function.
58
Why are function parameters useful?
To know what value(s) to pass through as the argument when calling a function.
59
What two effects does a return statement have on the behavior of a function?
* It causes the function to produce a value we can use in our program. * It will prevent any more code in the function's code block from being run.
60
What are arrays used for?
To store a list of values.
61
Describe array literal notation.
var array-name = []
62
How are arrays different from "plain" objects?
* They are numerically indexed. | * They are designed to be used as a list.
63
What number represents the first index of an array?
0.
64
What is the length property of an array?
• The number of values in an array.
65
How do you calculate the last index of an array?
array.length - 1.