Javascript Functions Basics Flashcards
When is the first expression in the parentheses for a for loop (known as the initialization) evaluated?
Executed ONLY 1x before loop starts
it’s only job is to set the variable for the loop start
When is the second expression in the parentheses for a for loop (known as the condition) evaluated?
Runs before each iteration
Defines the condition of the initial variable for loop to run.
Tells us when to stop when to stop
When is the third / final expression in the parentheses for a for loop evaluated?
Statement 3 is executed (every time) after the code block has been executed
& before the conditional expression
What is the purpose of the condition (stmt 2) in a for loop?
statement 2 is used to evaluate the condition of the initial variable.
If statement 2 returns true, the loop will start over again, if it returns false, the loop will end.
What is the purpose of the final expression in a for loop?
Increment or manipulate the value of initial variable until it is stopped by the condition
What does strictly equal mean?
===
checks whether two operands are EQUAL and returns BOOLEAN RESULT
What is the logical and operator?
&&
conjuncts 2 set of boolean operands.
returns result of TRUE only if all operands are true; otherwise returns result of FALSE
logical operators
&& and
|| or
! not (purpose is to flip the boolean)
Can you name some comparison operators?
== equal to === equal to & equal type != not equal !== not equal nor equal type >< >= <=
What are the five parts of a function definition?
- function keyword
- function name - opt.
- parameter lists (in parentheses in initial fxn def; serve as PLACEHOLDER for real values)
- code block / body of fxn;
in curly braces - return statement - (what should pop out of fxn when it is called and be assigned to variable) - opt.
How do you call a function?
functionName( argument(s) );
**no code block in { }
parameter vs argument
parameter in initial fxn declaration
it’s a local variable stored in the function
(SCOPE: can only be access from inside, not outside the fxn) (car window reflective - can look out but not in)
argument when fxn is called
Return
causes fxn to produce value when called
prevents the rest of code block from running (EXITS FUNCTION)
what is a function in JS?
fucntion is a set of code that we can use anytime by calling it
purpose of a loop
do something as fast as possible
like an assembly line