prep-javascript-functions, conditionals, and for-loops Flashcards

1
Q

What are the five parts of a function definition?

A
  1. the “function” keyword
  2. followed by a name
  3. parameters inside the parentheses
  4. followed by code to be executed that is enclosed in curly braces { }
  5. a return statement. What does calling the function produce?
    • it causes the function to produce a value when called
    • it prevents the rest of the code block from running (exits function)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you call a function?

A

A function can be called when an event occurs (i.e. user clicks a button), when it is invoked (called) from the JavaScript code, or automatically (self-invoked).

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

What is the difference between a parameter and an argument?

A

Function parameters are listed inside the parentheses in the function definition.

Function arguments are the values received when the function is invoked.

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

What does strictly equal mean?

A

Strictly equal means that two variables have values that are of the same or equal value and same or equal data type.

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

What is the logical “and” operator?

A

“&&” is the logical “and” operator.
If both conditions are true, “true” is returned.
If one of the conditions is false, “false” is returned.

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

Can you name some comparison operators?

A
  1. equal to (==)
  2. equal value and equal type (===)
  3. not equal (!=)
  4. not equal value or not equal type (!==)
  5. greater than (>)
  6. less than (less than sign goes here but Brainscape messes up when I enter it for some reason)
  7. greater than or equal to (>=)
  8. less than or equal to (<=)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When is the first expression in the parentheses for a for loop (known as the initialization) evaluated?

A

The first expression in the parentheses for a “for” loop (known as the initialization) is evaluated once before the loop begins or before the execution of the code block.

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

When is the second expression in the parentheses for a for loop (known as the condition) evaluated?

A

The second expression (the condition) is evaluated before each iteration of the loop. If the condition is true, the statement or code block is executed.

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

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

A

The purpose of the condition in a “for” loop is to evaluate whether or not to proceed executing the code block.
If the evaluation of the condition results in “true”, the statement or code block is executed. If it results in “false”, execution skips to the first expression following the “for” loop construct.

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

When is the third expression in the parentheses for a for loop (known as the final expression) evaluated?

A

The third expression (final expression) is evaluated after each loop iteration and just before the evaluation of the second expression (the condition).

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

What is the purpose of the final expression in a for loop?

A

The final expression is generally used to update or increment (or decrement) the counter variable.

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