Introduction - https://eloquentjavascript.net/00_intro.html
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
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:
- Store the number 0 in memory location 0.
- Store the number 1 in memory location 1.
- Store the value of memory location 1 in memory location 2.
- Subtract the number 11 from the value in memory location 2.
- If the value in memory location 2 is the number 0, continue with instruction 9.
- Add the value of memory location 1 to memory location 0.
- Add the number 1 to the value of memory location 1.
- Continue with instruction 3.
- 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
Written in 1995 by Brendan Eich in a weekend for Netscape Navigator.
It is liberal in what it allows.
Code - the text that makes up programs
- First 12 chapters discuss the JavaScript language
- Next 7 chapters are about web browsers and the way JavaScript is used to program them.
- Final two chapters are devoted to Node.js
- 5 project chapters
monospaced fonts represent elements of programs