Functions Flashcards

1
Q

functions

A
  • allows us to reuse blocks of code.
  • Allows is to wrap blocks of code into REUSABLE packages.
  • You call a function to execute the function. Similarly you run a program to execute its code.
  • mini programs inside your program
  • The main point of functions is to get rid of duplicate code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Argument

A
  • Value passed in the function call.
  • The input to functions are arguments
  • The output is the return value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Parameter

A

• Variable(s) in between the function’s parentheses in the definition statement.

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

return

A
  • sends back a value
  • can’t pass functions to variables without it.
  • Stops the execution of a function. This feature of “return” is similar in operation to “break”
  • Every function returns something, but if “return” is not explicitly used it always returns “undefined” after the output is printed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Function Declaration vs. Function Expression

A
//function declaration 
function test1() {
    return xyz;
}
//function expression
var test1 = function() {
    return xyz;
}
• two ways to declare a function 
• if the latter is used if you pass a different value the function is lost
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Scope

A
  • Context of what some code can be executed in
  • if you define a variable inside a function it can only be used inside the function. This is also known as local variable.
  • Variables that was declared outside the function can be accessed inside the function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Higher Order functions

A

• Any function that takes a function as an argument, returns a function or both.

setInterval(sing, 1000);  when you pass "sing" this way without () you passing the code so that setInterval will execute it. 
• setInterval(function(){
   //statement;
}); - used when you want to pass a function but don't know what it is yet.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Call

A

run or execute a function

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