Functions Flashcards

1
Q

Ho are functions defined in JS?

A

the function statement
example
function MyEasyFunction() {
console.log(‘My function was called’);
}//now call the function
myEasyFunction();

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

How can a function be defined as of E6?

A

Using arrow funtion syntax
const myEasyFunction = () => {
console.log(‘My arrow sytax’) ;
}

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

How can a parameter be defined for a function?

A

In parentheses like
myEasyFunction(param1){
or
const myEasyFunction = (param1) => {

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

How is data returned from a function?

A

Use the return command within the function. like
constr myEasyFunc = (par1,par2) => {
return par1 + par2;
}
//the call looks like
let mySum = myEasyFunc(100, 200);
/*this would return the value of mySum as 300 */

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

How can multiple parameters be defined for a function?

A

Separate the values with a comma like
function myEasyFunc(par1,par2) {

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

Describe a global closure?

A

It seems kind of like building an object
This involves creating a wrapper function to protect variables.
For example
const myPrice = (cost) => {
let myCost = cost; //wrapper variable
return (price = (markUp) => {
return (markUp += cost);
});
};
//use of the wrapper to build a
//new function with a set cost
const totPrice = myPrice(200);
let tenPerc = totPrice(20);
//would return 220 the main variable is protected

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