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
Q

How do you remove the last element from an array?

A

Using the Array.prototype.pop() method.

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

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

A

Using the Math.floor() method.

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

How do you generate a random number?

A

Using the Math.random() method.

28
Q

How do you delete an element from an array?

A

Using the Array.prototype.splice() method.

29
Q

How do you append an element to an array?

A

Using the Array.prototype.push() method.

30
Q

How do you break a string up into an array?

A

Using the String.prototype.split() method.

31
Q

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

A

They do not, they are immutable, and only reassign the variable. You would check by looking at the documentation or console log.

32
Q

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

A

About 30 string methods.

33
Q

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

A

No, you don’t always need to use the return value.

34
Q

Roughly how many array methods are there according to MDN Web Docs?

A

About 30 array methods.

35
Q

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

A

MDN.

36
Q

What is the purpose of a loop?

A

• To run a certain block of code as fast as possible until something tells it to stop.

37
Q

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

A

To tell the loop when to start and stop.

38
Q

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

A

Iteration means how many times the code in the loop runs.

39
Q

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

A

Before each pass through the loop.

40
Q

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

A

Once, before the loop begins.

41
Q

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

A

Before each loop iteration.

42
Q

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

A

At the end of each loop iteration.

43
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.

44
Q

What does the ++ increment operator do?

A

It increments a number up by one.

45
Q

How do you iterate through the keys of an object?

A

By using a for…in loop.

46
Q

Give 6 examples of comparison operators.

A
  • >
    • (Greater Than)
  • < - (Less Than)
  • === - (Strictly Equal To)
  • == - (Equal To)
  • != - (Is Not Equal To)
  • !== - (Strictly Not Equal To)
47
Q

What data type do comparison expressions evaluate to?

A

Boolean.

48
Q

What is the purpose of an if statement?

A

• To make decisions in our code.

49
Q

Is else required in order to use an if statement?

A

No.

50
Q

Describe the syntax (structure) of an if statement.

A
  • if Keyword
  • condition
  • code block
51
Q

What are the three logical operators?

A
  • && - (Logical And)
  • || - (Logical Or)
  • ! - (Logical Not)
52
Q

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

A

By using a logical operator.

53
Q

What is a function in JavaScript?

A

A series of steps that are performed when they are called and passed a value.

54
Q

Describe the parts of a function definition.

A
  • The Function Keyword.
  • The name of the function (optional).
  • Parameters surrounded by parentheses.
  • The function’s code block {}.
  • Return Statement (optional).
55
Q

Describe the parts of a function call.

A
  • Function Name.

* (Arguments).

56
Q

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

A
  • The function definition holds all the code.

* The function call runs the code.

57
Q

What is the difference between a parameter and an argument?

A
  • A parameter is a placeholder.

* An argument is what is passed through the function when we call a function.

58
Q

Why are function parameters useful?

A

To know what value(s) to pass through as the argument when calling a function.

59
Q

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

A
  • 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
Q

What are arrays used for?

A

To store a list of values.

61
Q

Describe array literal notation.

A

var array-name = []

62
Q

How are arrays different from “plain” objects?

A
  • They are numerically indexed.

* They are designed to be used as a list.

63
Q

What number represents the first index of an array?

A

0.

64
Q

What is the length property of an array?

A

• The number of values in an array.

65
Q

How do you calculate the last index of an array?

A

array.length - 1.