Eloquent JavaScript - Chapter 1 & 2 Flashcards
half of 100 is ${100 / 2}
will output what? What is it called when you use ` ` to surround a string?
half of 100 is 50
a template literal
&& is a what and what does it represent?
when is && true?
&& is a logical operator.
it represents logical “and”
when both values are true
|| is a what and what does it mean?
when is || true?
|| is a logical operator.
it represents logical “or”
when one value is true
What do the operators === and !== do?
How is this different than == and !=?
These operators test whether a value is precisely equal to the other (===) or not precisely equal (!==). They rule out any automatic type conversions.
console.log(true ? 1 : 2); // → Why?
1
Because the first value is true, the ternary operator picks the middle value as a result.
console.log(false ? 1 : 2); // → Why?
2
Because the first value is false, the ternary operator picks the middle value as a result.
What are the three main bindings?
How do they each hold value?
let, var and const let = var = const = used for values that will never be changed later in a program.
Executing a function is called _____?
invoking, calling or applying it
Executing a function is called _____?
invoking, calling or applying it
Values given to functions are called ____?
arguments
console.log(Math.max(2, 4)); // →
4
returns the highest number
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.)
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”.
let number = 0; while (number <= 12) { console.log(number); number = number + 2; } // →
// 2 // 4 // 6 // etcetera...
What is this program doing?
let yourName; do { yourName = prompt("Who are you?"); } while (!yourName); console.log(yourName);
it is prompting the user to input a name. until the user inputs a string that isn’t empty it will keep asking.
What is the % operator called and what does it do?
What is 50 % 5?
The % operator is called the remainder operator. It looks for a number that is divisible by the next number.
50 % 5 = 10