prep-javascript-functions, conditionals, and for-loops Flashcards
What are the five parts of a function definition?
- the “function” keyword
- followed by a name
- parameters inside the parentheses
- followed by code to be executed that is enclosed in curly braces { }
- 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 do you call a function?
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).
What is the difference between a parameter and an argument?
Function parameters are listed inside the parentheses in the function definition.
Function arguments are the values received when the function is invoked.
What does strictly equal mean?
Strictly equal means that two variables have values that are of the same or equal value and same or equal data type.
What is the logical “and” operator?
“&&” is the logical “and” operator.
If both conditions are true, “true” is returned.
If one of the conditions is false, “false” is returned.
Can you name some comparison operators?
- equal to (==)
- equal value and equal type (===)
- not equal (!=)
- not equal value or not equal type (!==)
- greater than (>)
- less than (less than sign goes here but Brainscape messes up when I enter it for some reason)
- greater than or equal to (>=)
- less than or equal to (<=)
When is the first expression in the parentheses for a for loop (known as the initialization) evaluated?
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.
When is the second expression in the parentheses for a for loop (known as the condition) evaluated?
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.
What is the purpose of the condition in a for loop?
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.
When is the third expression in the parentheses for a for loop (known as the final expression) evaluated?
The third expression (final expression) is evaluated after each loop iteration and just before the evaluation of the second expression (the condition).
What is the purpose of the final expression in a for loop?
The final expression is generally used to update or increment (or decrement) the counter variable.