The Language Flashcards

1
Q

What is this scientific notation equal to?

2.998e8

A

2.998 x 10^8 = 299,800,000

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

What result do you get when you try to calculate any number of other numeric operations that don’t yield a precise, meaningful result.

A

NaN.

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

What are the characters you get when you press enter?

A

Newlines

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

How do you escape a character?

A

\

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

How do you create a newline?

A

\n

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

How do you create a tab character?

A

\t

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

What does the typeof operator do?

A

Typeof produces a string value naming the type of the value you give it.

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

Can strings be compared using booleans?

A

Yes. Ex: console.log(“Aardvark”

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

Are uppercase letters “less than” or “more than” lowercase letters?

A

uppercase letters are always “less” than lowercase ones, so “Z”

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

What value in Javascript is not equal to itself?

A
NaN. console.log(NaN == NaN)
// -> false

NaN is supposed to denote the result of a nonsensical computation, and as such, it isn’t equal to the result of any other nonsensical computations.

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

When is the logical “and” operator true?

A
console.log(true && false)
// → false
console.log(true && true)
// → true

It is a binary operator, and its result is true only if both the values given to it are true.

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

When is the logical “or” operator true?

A

It produces true if either of the values given to it is true.

console.log(false || true)
// → true
console.log(false || false)
// → false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What kind of operator is the “not” operator and what does it do?

A

Not is written as an exclamation mark (!). It is a unary operator that flips the value given to it—!true produces false and !false gives true.

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

How does precedence work with standard boolean operators?

A

|| has the lowest precedence, then comes &&, then the comparison operators (>, ==, and so on), and then the rest.

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

What is the “conditional” operator also called and how does it work?

A

Sometimes just called the “ternary” operator since it is the only such operator in the language). The value on the left of the question mark “picks” which of the other two values will come out. When it is true, the middle value is chosen, and when it is false, the value on the right comes out.

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

What do the following expressions result in?

console. log(8 * null)
console. log(“5” - 1)
console. log(“5” + 1)
console. log(“five” * 2)
console. log(false == 0)

A
console.log(8 * null)
// → 0
console.log("5" - 1)
// → 4
console.log("5" + 1)
// → 51
console.log("five" * 2)
// → NaN
console.log(false == 0)
// → true
17
Q

Define what “coercion” is. What’s another term for it?

A

Automatic type conversion. When an operator is applied to the “wrong” type of value, JavaScript will quietly convert that value to the type it wants, using a set of rules that often aren’t what you want or expect. This is called type coercion.

18
Q

When is the last behavior below useful?

console.log(null == undefined);
// → true
console.log(null == 0);
// → false
A

That last piece of behavior is often useful. When you want to test whether a value has a real value instead of null or undefined, you can simply compare it to null with the == (or !=) operator.

19
Q

When converting strings and numbers to Boolean values, what 3 values count as false?

A

The rules for converting strings and numbers to Boolean values state that 0, NaN, and the empty string (“”) count as false, while all the other values count as true.

20
Q

What is “short-circuit evaluation”?

A

In the case of true || X, no matter what X is—even if it’s an expression that does something terrible—the result will be true, and X is never evaluated. The same goes for false && X, which is false and will ignore X.

21
Q

Define an “expression”

A

A fragment of code that produces a value is called an expression. Every value that is written literally (such as 22 or “psychoanalysis”) is an expression. An expression between parentheses is also an expression, as is a binary operator applied to two expressions or a unary operator applied to one.

22
Q

What is the simplest kind of statement?

A

The simplest kind of statement is an expression with a semicolon after it. This is a program:

1;
!false;

23
Q

When the = operator is used on existing variables, what does it do to the variable?

A

When a variable points at a value, that does not mean it is tied to that value forever. The = operator can be used at any time on existing variables to disconnect them from their current value and have them point to a new one.

var mood = "light";
console.log(mood);
// → light
mood = "dark";
console.log(mood);
// → dark
24
Q

What are other words used to mean that you are executing a function?

A

Executing a function is called invoking, calling, or applying it.

25
Q

When are functions useful without “side effects”?

A

Showing a dialog box or writing text to the screen is a side effect. A lot of functions are useful because of the side effects they produce. Functions may also produce values, and in that case, they don’t need to have a side effect to be useful.

26
Q

What kind of execution is an “if” statement?

A

Conditional execution.

27
Q

Define a “block”

A

Whenever we need to execute multiple statements inside a loop, we wrap them in curly braces ({ and }). Braces do for statements what parentheses do for expressions: they group them together, making them count as a single statement. A sequence of statements wrapped in braces is called a block.

28
Q

Write a program that calculates and shows the value of 2^10

A
var result = 1;
var counter = 0;
while (counter
29
Q

What is the difference between and “do” and “while” loop?

A

The do loop is a control structure similar to the while loop. It differs only on one point: a do loop always executes its body at least once, and it starts testing whether it should stop only after that first execution. To reflect this, the test appears after the body of the loop:

do {
  var yourName = prompt("Who are you?");
} while (!yourName);
console.log(yourName);
30
Q

Using a for loop, write a program that calculates and shows the value of 2^10.

A
var result = 1;
for (var counter = 0; counter
31
Q

What does “breaking out of a loop” mean and how do you do it?

A

Having the loop’s condition produce false is not the only way a loop can finish. There is a special statement called break that has the effect of immediately jumping out of the enclosing loop.

This program illustrates the break statement. It finds the first number that is both greater than or equal to 20 and divisible by 7.

for (var current = 20; ; current++) {
  if (current % 7 == 0)
    break;
}
console.log(current);
// → 21