Javascript Functions Basics Flashcards

1
Q

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

A

Executed ONLY 1x before loop starts

it’s only job is to set the variable for the loop start

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

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

A

Runs before each iteration

Defines the condition of the initial variable for loop to run.

Tells us when to stop when to stop

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

When is the third / final expression in the parentheses for a for loop evaluated?

A

Statement 3 is executed (every time) after the code block has been executed

& before the conditional expression

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

What is the purpose of the condition (stmt 2) in a for loop?

A

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.

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

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

A

Increment or manipulate the value of initial variable until it is stopped by the condition

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

What does strictly equal mean?

A

===

checks whether two operands are EQUAL and returns BOOLEAN RESULT

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

What is the logical and operator?

A

&&

conjuncts 2 set of boolean operands.
returns result of TRUE only if all operands are true; otherwise returns result of FALSE

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

logical operators

A

&& and
|| or
! not (purpose is to flip the boolean)

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

Can you name some comparison operators?

A
== equal to
=== equal to & equal type
!= not equal
!== not equal nor equal type
><
>=
<=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the five parts of a function definition?

A
  1. function keyword
  2. function name - opt.
  3. parameter lists (in parentheses in initial fxn def; serve as PLACEHOLDER for real values)
  4. code block / body of fxn;
    in curly braces
  5. return statement - (what should pop out of fxn when it is called and be assigned to variable) - opt.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you call a function?

A

functionName( argument(s) );

**no code block in { }

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

parameter vs argument

A

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

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

Return

A

causes fxn to produce value when called

prevents the rest of code block from running (EXITS FUNCTION)

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

what is a function in JS?

A

fucntion is a set of code that we can use anytime by calling it

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

purpose of a loop

A

do something as fast as possible

like an assembly line

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

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

A

each time loop runs until condition is false

17
Q

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

A

before code block executes even if condition is false

18
Q

for loop details (in debugger)

A

work
expression
final condition

19
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

20
Q

How do you iterate through the keys of an object?

A

the “for…in” loop

for (var key in object)

21
Q

how to choose which loop?

A

for. .. in = properties/keys
for. .. of = values

while loop = when you don’t know how long / how many times something has to be done
(ex/ drink until no longer thirst, no idea how long thirst is)

for loop = when you know # of times you need to iterate