Eloquent JavaScript - Chapter 1 & 2 Flashcards

1
Q

half of 100 is ${100 / 2} will output what? What is it called when you use ` ` to surround a string?

A

half of 100 is 50

a template literal

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

&& is a what and what does it represent?

when is && true?

A

&& is a logical operator.
it represents logical “and”
when both values are true

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

|| is a what and what does it mean?

when is || true?

A

|| is a logical operator.
it represents logical “or”
when one value is true

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

What do the operators === and !== do?

How is this different than == and !=?

A

These operators test whether a value is precisely equal to the other (===) or not precisely equal (!==). They rule out any automatic type conversions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
console.log(true ? 1 : 2);
// → 
Why?
A

1

Because the first value is true, the ternary operator picks the middle value as a result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
console.log(false ? 1 : 2);
// → 
Why?
A

2

Because the first value is false, the ternary operator picks the middle value as a result.

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

What are the three main bindings?

How do they each hold value?

A
let, var and const
let =
var =
const = used for values that will never be changed later in a program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Executing a function is called _____?

A

invoking, calling or applying it

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

Executing a function is called _____?

A

invoking, calling or applying it

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

Values given to functions are called ____?

A

arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
console.log(Math.max(2, 4));
// →
A

4

returns the highest number

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

What is this program doing?

let theNumber = Number(prompt(“Pick a number”));
if (!isNaN(theNumber)) {
console.log(“Your number is the square root of “ +
theNumber * theNumber);
}
What is (!isNaN(theNumber)) doing? (!isNaN is the function and (theNumber) is the argument.)

A

It is prompting the user to pick a number. then it is determining if the value input by the user is an actual number. if it is a number then the square root will be given.
(!isNaN(theNumber)) - The isNaN function is a standard JavaScript function that returns true only if the argument it is given is NaN. The Number function happens to return NaN when you give it a string that doesn’t represent a valid number. Thus, the condition translates to “unless theNumber is not-a-number, do this”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
let number = 0;
while (number <= 12) {
  console.log(number);
  number = number + 2;
}
// →
A
// 2
// 4
// 6
// etcetera...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is this program doing?

let yourName;
do {
  yourName = prompt("Who are you?");
} while (!yourName);
console.log(yourName);
A

it is prompting the user to input a name. until the user inputs a string that isn’t empty it will keep asking.

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

What is the % operator called and what does it do?

What is 50 % 5?

A

The % operator is called the remainder operator. It looks for a number that is divisible by the next number.

50 % 5 = 10

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

What do the break and continue statements do?

A

Break; will stop the program or loop and jump out of it. By using an if statement with a for loop, you can break out of a loop when a certain condition is met.

Continue; when encountered in a loop, control will jump out of the body and continues with the next loops iteration.

17
Q

What does the default statement do?

A

Default will output a given value or statement if the input received is not recognized or categorized by the program.

18
Q

What is the syntax for invoking a function?

A

functionName(argument1, argument2)

ex. calculate(num1, num2)