- Exercises and notes from the book http://eloquentjavascript.net/
- Started as preparation for Lambda University, July 3, 2017
- Chapters 3 and 4 assigned as pre-Course homework
Chapter 3 - Functions
"People think that computer science is the art of geniuses but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones." -Donald Knuth
-
Defining a Function
"Some functions produce a value, such as power and square, and some don’t, such as makeNoise, which produces only a side effect. A return statement determines the value the function returns. When control comes across such a statement, it immediately jumps out of the current function and gives the returned value to the code that called the function. The return keyword without an expression after it will cause the function to return undefined."
-
Parameters and Scopes
"The parameters to a function behave like regular variables, but their initial values are given by the caller of the function, not the code in the function itself ... An important property of functions is that the variables created inside of them, including their parameters, are local to the function ... "
-
Nested Scope
-
Functions as Values
-
Declaration Notation
-
The Call Stack
-
Optional Arguments
-
Closure
-
Recursion
-
Growing Functions
"How difficult it is to find a good name for a function is a good indication of how clear a concept it is that you’re trying to wrap."
-
Functions and Side Effects
Functions that create values are easier to combine in new ways than functions that directly perform side effects.
-
Summary
The function keyword, when used as an expression, can create a function value. When used as a statement, it can be used to declare a variable and give it a function as its value.
-
Exercises
- Minimum
- Recursion
- Bean Couting
- Why doesn't this work with the .forEach loop? Maybe I need to split it into a proper array? Ah... yes, apparently forEach is only available with arrays? Also, "for" loops are apparently consideraly faster.
Chapter 4 - Data Structures: Objects and Arrays
"On two occasions I have been asked, ‘Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?’ [...] I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -Charles Babbage, Passages from the Life of a Philosopher (1864)
-
The Weresquirrel
-
Data Sets
-
Properties
When using a dot, the part after the dot must be a valid variable name, and it directly names the property. When using square brackets, the expression between the brackets is evaluated to get the property name. Whereas value.x fetches the property of value named “x”, value[x] tries to evaluate the expression x and uses the result as the property name.
-
Methods
-
Objects
-
Mutability
When we have two numbers, 120 and 120, we can consider them precisely the same number, whether or not they refer to the same physical bits. But with objects, there is a difference between having two references to the same object and having two different objects that contain the same properties.
- [04.06.js](ch04-data-structures_objects-arrays/04.06.js)
-
The Lycanthrope's Log
-
Computing Correlation
-
Objects as Maps
-
The Final Analysis
-
Further Arrayology
-
Strings and their Properties
-
The Arguments Object
-
The Math Object
Many languages will stop you, or at least warn you, when you are defining a variable with a name that is already taken. JavaScript does neither, so be careful.
-
The Global Object
-
Summary
Objects can also serve as maps, associating values with names. The in operator can be used to find out whether an object contains a property with a given name. The same keyword can also be used in a for loop (for (var name in object)) to loop over an object’s properties.
-
Exercises
Chapter 5 - Higher Order Functions
"Tzu-li and Tzu-ssu were boasting about the size of their latest programs. ‘Two-hundred thousand lines,’ said Tzu-li, ‘not counting comments!’ Tzu-ssu responded, ‘Pssh, mine is almost a million lines already.’ Master Yuan-Ma said, ‘My best program has five hundred lines.’ Hearing this, Tzu-li and Tzu-ssu were enlightened." -Master Yuan-Ma, The Book of Programming
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies." -C.A.R. Hoare, 1980 ACM Turing Award Lecture
Chapter 20 - Node.js
- Background
- Asynchronicity