Functions Flashcards

1
Q

What is a function?

A

a function is a procedure that lets you extract code and run it as a separate unit

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

what is a function name without parentheses?

A

Without parentheses a function like funcName() is not a function call but simply the name of the function. The value being a function object representing the function in question

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

what scope do parameters have?

A

Parameters arelocal variablesonly available within the function’s body

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

What happens when you nest a function in another function?

A

These are private functions which can only be called within the parent functions definition.

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

What scope do function names have?

A

Function names are either global or local, depending on whether the function is at the program’s top level or nested inside a class, object, or another function.

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

What are arguments?

A

Arguments are objects or primitive values passed to a function

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

What are parameters?

A

parameters are declarations for the local variables used inside the function to access the arguments.

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

What happens if you provide too few/too many arguments?

A

If you provide too few arguments, the parameters and variables that correspond to the missing arguments will receive a value ofundefined. Additional arguments will be ignored if you provide too many

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

What is a function which only returns a boolean called?

A

A predicate

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

What is the implicit return value of most JS functions?

A

Undefined

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

What is an explicit return value?

A

An explicit return value is when you provide an specific overriding return in the function definition

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

how do you define default parameters?

A

function say(text = “hello”) {
console.log(text + “!”);
}

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

How is a method different than a function? How can we tell the difference?

A

Methods are functions built into existing objects. We can tell because they use a period for invocation. ‘xyzzy’.toUpperCase()

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

What’s the difference between reassignment and mutation?

A

To change a variable can either change what value is assigned (orbound) to a variable or we can change the value of the thing that is bound to the variable. The former is known asreassignmentwhile the latter is known asmutation.

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

Can we change primitives?

A

No. Primitive values are immutable.

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

What is function composition?

A

Function composition is when we use a function call as an argument to another function. Because all function calls evaluate to a value, this is the same as passing the return value of the second function to the first.

17
Q

What are the three ways of defining a function?

A

Function declaration,
Function expressions, and arrow functions

18
Q

which methods of function definition allow you to call a function before it is defined.

A

Only function declaration

19
Q

What is function declaration?

A

function functionName(zeroOrMoreArguments…) {
// function body
}

20
Q

What is a function expression?

A

let greetPeople = function () {
console.log(“Good Morning!”);
};

Any function definition that doesn’t have the word function at the very beginning is a function expression.

21
Q

What does it mean that JS functions are ‘first-class-functions’?

A

This means that JS treats functions like any other variable. Which in fact they are, all JavaScript functions are objects

22
Q

how do you define an arrow function?

A

let add = (a, b) => a + b;

23
Q

Can we omit return statements in arrow functions?

A

We can omit return statements in arrow functionswhen and only when the function body contains a single expression that is not itself surrounded by curly braces

24
Q

Can parameter parentheses can only be omitted in arrow functions?

A

parameter parentheses can only be omitted if the function has a single simple parameter

25
Q

What is the call stack?

A

the call stack is a mechanism for an interpreter (like the JavaScript interpreter in a web browser) to keep track of its place in a script that calls multiple functions — what function is currently being run and what functions are called from within that function, etc.

26
Q

What order does JS add/remove frames from the call stack

A

the call stack puts information about the current function on the top of the stack, then removes that information when the function returns.

27
Q

What are the units on the call stack called?

A

Stack Frames

28
Q

What is the initial stack frame referred to as?

A

The main function

29
Q

What is a limitation of recursive functions?

A

recursive functions can break the call stack by exceeding the call stack length if they keep calling themselves too many times.