Eloquent Javascript Chapter 1: Values, Types, Operators Flashcards

1
Q

Javascript vs. other languages

A

More liberal in what it allows. Good for flexibility, but makes it difficult to troubleshoot.

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

Bits

A

All data is stored as bits, any kind of two-valued thing (usually 0’s and 1’s). The weight of each 0 or 1 increases from right to left.

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

6 Types of Values

A

numbers, strings, Booleans, objects, functions, undefined values

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

Javascript and accuracy re: fractional numbers

A

Calculations not always accurate because numbers are stored using 64 bits.

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

Operators

A

Any symbol that causes an operation to occur: +, *, -, /, %

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

% Operator

A

The remainder or modulo operator. X % Y provides the remainder of dividing X by Y.

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

3 Special Numbers

A

Considered numbers but don’t behave like normal numbers: infinity, -infinity, NaN

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

NaN

A

Not a number - results from any operation that doesn’t yield a precise result, such as 0/0, infinity-infinity, etc.

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

Strings

A

Text in quotes. Can be marked with single and double quotes as long as beginning and end quotes match.

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

Escaping the character

A

Need to “escape” the character with a backslash before certain characters, such as quotes within quotes and enters/newlines. \n = newline, \t = tab. Actual backslash is \.

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

Concatenating strings

A

“text” + “text” = “texttext”

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

Binary operators

A

Operators that take two values: 1-2, 2+3, 3>1

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

Unary operators

A

Operators that take just one value. Includes operators that are not symbols, but words. Includes minus operator that can be used to make something negative. typeof() for example is a unary operator.

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

console.log

A

Show result on screen. Ultimate appearance depends on Javascript environment chosen to run.

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

Boolean values

A

Has only two possible values, true and false. console.log(3>2) results in true.

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

Comparisons

A

Using >, <=, >=, ==, !=. Note that the latter two are imprecise and sometimes value types can be changed. Alternately, use === and !== for exact values.

17
Q

Can strings be compared with >,

A

Yes - they are compared based on Unicode standard, which assigns numbers to each character. Uppercase letters are valued less than lowercase ones.

18
Q

3 Logical operators

A

and (&&), or (||), not(!). These can be applied to Boolean values/used to reason about Booleans.

19
Q

&& vs. || precedence

A

&& has greater precedence than ||.

20
Q

Ternary operator

A

Choice between two values is decided by a third. true ? 1 : 2 will return left value, false ? 1 : 2 will return right value.

21
Q

2 Undefined values

A

null, undefined. Denote the absence of meaningful value, but are still values themselves. Are more or less interchangeable. Note that javascript might interpret null as 0. console.log(null==undefined) is true. console.log(null == 0) is false.

22
Q

Type coercion

A

When an operator is applied to the “wrong” type of value, JavaScript will convert that value to the type it wants, with often unexpected/unwanted results. If NaN appears where unexpected, may be result of accidental type conversions.

23
Q

Short-circuit evaluation

A

|| and && can return either left or right value. For ||, will return left value if it evaluates as true, else right value. && works opposite way, taking left if evaluates as false. This can be used to produce default values in the case that the left value evaluates as an NaN.