Skip to content

Instantly share code, notes, and snippets.

@AdamMescher
Last active November 6, 2019 01:14
Show Gist options
  • Select an option

  • Save AdamMescher/5c9d1cde533be5d5b20e401f4d4ccf86 to your computer and use it in GitHub Desktop.

Select an option

Save AdamMescher/5c9d1cde533be5d5b20e401f4d4ccf86 to your computer and use it in GitHub Desktop.
Eloquent Javascript: A Modern Introduction to Programming

Programming - the act of constructing a program Program - set of precise instructions telling a computer what to do Programming Language - An artifically constructed language used to instruct computers

On Programming

Programming is hard and learning is hard work. Keep at it.

A program is a building of thought.

Example problem: Add the numbers from 1 to 10 together and print the result

In the beginning

00110001 00000000 00000000
00110001 00000001 00000001
00110011 00000001 00000010
01010001 00001011 00000010
00100010 00000010 00001000
01000011 00000001 00000000
01000001 00000001 00000001
00010000 00000010 00000000
01100010 00000000 00000000

English steps:

  1. Store the number 0 in memory location 0.
  2. Store the number 1 in memory location 1.
  3. Store the value of memory location 1 in memory location 2.
  4. Subtract the number 11 from the value in memory location 2.
  5. If the value in memory location 2 is the number 0, continue with instruction 9.
  6. Add the value of memory location 1 to memory location 0.
  7. Add the number 1 to the value of memory location 1.
  8. Continue with instruction 3.
  9. Output the value of memory location 0.

Using names instead of numbers for the instructions and memory locations helps

Set “total” to 0.
 Set “count” to 1.
[loop]
 Set “compare” to “count”.
 Subtract 11 from “compare”.
 If “compare” is zero, continue at [end].
 Add “count” to “total”.
 Add 1 to “count”.
 Continue at [loop].
[end]
 Output “total”

In JavaScript:

let total = 0;
let count = 1;
while (count <= 10) {
 total += count;
 count += 1;
}
console.log(total);

Potential refactor, if sum() and range() functions existed:

console.log(sum(range(1,10));

A good programming language:

  • Helps the programmer by allowing them to talk about the actions that the computer has to perform on a higher level
  • Helps omit details
  • Provides conventient building blocks
  • Allows the definition of custom building blocks
  • Makes custom blocks easy to create

What is JavaScript?

Written in 1995 by Brendan Eich in a weekend for Netscape Navigator.

It is liberal in what it allows.

Code and what to do with it

Code - the text that makes up programs

Overview of the book

  1. First 12 chapters discuss the JavaScript language
  2. Next 7 chapters are about web browsers and the way JavaScript is used to program them.
  3. Final two chapters are devoted to Node.js
  • 5 project chapters

Typographic Conventions

monospaced fonts represent elements of programs

Chapter 1: Values, Types and Operators - https://eloquentjavascript.net/01_values.html

13 in binary

  0  0  0  0 1 1 0 1
128 64 32 16 8 4 2 1

Binary number 00001101

Non-zero digits stand for 8, 4, and 1. They add up to 13.

Values

Values - chucnks that represent pieces of information.

Every value has a type.

To create a value, invoke its name.

Numbers

Strings

Unary Operators

Boolean Values

Empty Values

Automatic Type Conversion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment