functions Flashcards

1
Q

A function definition is a regular _______ where the value of the binding is a function.

A

binding

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

Functions have a set of parameters and a ______, which contains the statements that are to be executed when the function is called.

A

body

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

Some functions produce a value, such as power and square, and some don’t whose only result is a _____ _____.

A

side effect

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

A ______ statement determines the value the function returns.

A

return

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

A return keyword without an expression after it will cause the function to return ________.

A

undefined

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

Functions that don’t have a return statement at all return _________.

A

undefined

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

Parameters to a function behave like regular bindings, but their initial values are given by the _____ of the function, not the code in the function itself.

A

caller

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

Each binding has a ______, which is the part of the program in which the binding is visible.

A

scope

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

or bindings defined outside of any function or block, the scope is the whole program—you can refer to such bindings wherever you want. These are called _____.

A

global

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

Bindings created for function parameters or declared inside a function can be referenced only in that function, so they are known as _____ bindings.

A

local

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

Bindings declared with let and const are _____ to the block that they are declared in.

A

local

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
let x = 10;
if (true) {
  let y = 20;
  var z = 30;
  console.log(x + y + z);
}

console.log(x + z);

what are both outputs?

A

60
40

var z is visible outside its block once declared

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

Old-style bindings, created with the ______ keyword, are visible throughout the whole function that they appear in—or throughout the global scope, if they are not in a function.

A

var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
const halve = function(n) {
  return n / 2;
};
let n = 10;
console.log(halve(100));

console.log(n);

what are the outputs?

A

50

10

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

________ scoping (sometimes known as static scoping ) is a convention used with many programming languages that sets the scope (range of functionality) of a variable so that it may only be called (referenced) from within the block of code in which it is defined. The scope is determined when the code is compiled.

A

Lexical

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

Arrow functions were added in 2015, mostly to make it possible to write small function expressions in a less _______ way.

A

verbose

17
Q

In Javascript you are allowed to enter too many or too few arguments to a function. T/F

A

true

18
Q

If you pass too many arguments to a function, the extra ones are ________.

A

ignored

19
Q

If you write an = operator after a parameter, followed by an expression, the value of that expression will ______ the argument when it is not given.

A

replace

makes it the default value

20
Q

Being able to reference a specific instance of a local binding in an enclosing scope—is called _______.

A

closure

21
Q

A function that references bindings from local scopes around it is called __ _____.

A

a closure

22
Q
function multiplier(factor) {
  return number => number * factor;
}
let twice = multiplier(2);
console.log(twice(5));

what is the ouput?

A

10

multiplier is called and creates an environment in which its factor parameter is bound to 2. The function value it returns, which is stored in twice, remembers this environment. So when that is called, it multiplies its argument by 2.

23
Q

A function that calls itself is called _________.

A

recursive

24
Q

A ______ function is a specific kind of value-producing function that not only has no side effects but also doesn’t rely on side effects from other code.

A

pure