Functions Flashcards

1
Q

Arrow Functions (ES6)

A

Does not require the ‘function’ keyword, and uses a fat arrow (=>) to separate the parameters from the body

Arrow functions with a single parameter do not need () around the parameter list
const checkAge = age => { //do something}

Arrow functions with a single expression do not require the use of the return keyword
const multiple = (a, b) => a*b;

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

Anonymous Functions

A

Functions that do not have a name property

const rocketToMars = function() {
return ‘BOOM!’;
}

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

Function Expression

A

Create functions inside an expression instead of as a function declaration. They can be anonymous and/or assigned to a value

const dog = function() {
return ‘Woof!’;
}

const dog = () => ‘Woof!’;

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

Parameters

A

Used as variables inside the function body
When a function is called, these parameters will have the value of whatever is passed in as arguments

function sayHello(name) {
return Hello, ${name}!;
}

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

return

A

Used to return (pass back) values from functions

If a return value is not specified, the function will return undefined by default

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

Calling functions

A

Functions can be called or executed using parentheses following the function name

// Defining the function
function sum(num1, num2) {
return num1 + num2;
}

// Calling the function
sum(2, 4); // 6

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

Global Scope

A

A value/function in the global scope can be used anywhere in the entire program

Variables declared outside of blocks or functions exist in the global scope

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

File/Module Scope

A

A value/function in the file/module scope can only be accessed within that file

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

Block Scope

A

A value/function is only visible/accessible within a code block { … }

const and let are block-scoped variables

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