Eloquent Javascript Chapter 1: Values, Types, Operators Flashcards
Javascript vs. other languages
More liberal in what it allows. Good for flexibility, but makes it difficult to troubleshoot.
Bits
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.
6 Types of Values
numbers, strings, Booleans, objects, functions, undefined values
Javascript and accuracy re: fractional numbers
Calculations not always accurate because numbers are stored using 64 bits.
Operators
Any symbol that causes an operation to occur: +, *, -, /, %
% Operator
The remainder or modulo operator. X % Y provides the remainder of dividing X by Y.
3 Special Numbers
Considered numbers but don’t behave like normal numbers: infinity, -infinity, NaN
NaN
Not a number - results from any operation that doesn’t yield a precise result, such as 0/0, infinity-infinity, etc.
Strings
Text in quotes. Can be marked with single and double quotes as long as beginning and end quotes match.
Escaping the character
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 \.
Concatenating strings
“text” + “text” = “texttext”
Binary operators
Operators that take two values: 1-2, 2+3, 3>1
Unary operators
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.
console.log
Show result on screen. Ultimate appearance depends on Javascript environment chosen to run.
Boolean values
Has only two possible values, true and false. console.log(3>2) results in true.