Chap. 3 eloquent javascript Flashcards

1
Q

Functions that don’t have a return statement at all, such as makeNoise, similarly return_____________.

A

undefined

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

// IS Y VISIBLE?

A

// y is not visible here

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

// what keyword to use to make Y NOT visible and Z VISBLE

A

let Y

var Z

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

FUNCTION DECLARTION OR EXPRESSION

function square(x) {
  return x * x;
}
A

FUNCTION DECLARTION

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

_____________are not part of the regular top-to-bottom flow of control.

A

Function declarations

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

FUNCTION DECLARTION OR EXPRESSION

var square = function(x){
  return x * x;
}
A

FUNCTION EXPRESSION

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

The main difference between a function expression and a function statement is the function name, which can be omitted in function expressions to ________

A

create anonymous functions.

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

CONDENSE the code:

const square1 = (x) => { return x * x; };

A

const square1 = x => x * x;

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

//Write out as a arrow function

function funcName(params) {
   return params + 2;
 }
A

var funcName = (params) => params + 2

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

When an arrow function has no parameters at all, its parameter list is just ______________.

A

an empty set of parentheses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
function greet(who) {
  console.log("Hello " + who);
}
greet("Harry");
console.log("Bye");
A

“Hello Harry”

“Bye”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
function square(x) { return x * x; }
console.log(square(4, true, "hedgehog"));
// →
A

// → 16

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

We defined function with only one parameter. Yet when we call it with three, the language doesn’t complain. It ignores the extra arguments and computes the square of the ______

A

first argument

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

If you pass too few, the missing parameters in a function get assigned the value ____________

A

undefined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
function minus(a, b) {
  if (b === undefined) return -a;
  else return a - b;
}

console. log(minus(10));
console. log(minus(10, 5));

A
// → -10
// → 5
17
Q

console.log(undefined === undefined);

A

TRUE

18
Q

TRUE OR FALSE

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

A

TRUE

19
Q

A function that calls itself is called___________.

A

recursive

20
Q

When you only have one parameter in an arrow function, the opening parenthesis are optional:

TRUE OR FALSE

A

TRUE

https://codeburst.io/javascript-arrow-functions-for-beginners-926947fc0cdc

21
Q

In a arrow function if you are returning an expression, you remove ____________

A

the brackets

22
Q
var myCar = new Car('Ford', 'Escape');
console.log(myCar);
// ?
A

=> Car {make: “Ford”, model: “Escape”}

23
Q
function add(c, d) {
  console.log(this.a + this.b + c + d);
}
add(3,4);
// logs  and why
A

NaN

a and b are undefined