عن كتاب عالم جافا سكريبت Eloquent JavaScript:
هو كتاب يشرح أمثلة على لغة جافا سكريبت وهو مستوى متوسط
Eloquent JavaScript
A Modern Introduction to Programming
Marijn Haverbeke
Contents
On programming
. . . . . . . . . . . . . . . . . . . . . . . . . . 2
Why language matters
. . . . . . . . . . . . . . . . . . . . . . . 4
What is JavaScript?
. . . . . . . . . . . . . . . . . . . . . . . . . 6
Code, and what to do with it
. . . . . . . . . . . . . . . . . . . 8
Overview of this book
. . . . . . . . . . . . . . . . . . . . . . . . 9
Typographic conventions
. . . . . . . . . . . . . . . . . . . . . . 10
1 Values, Types, and Operators
11
Values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Numbers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Strings
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Unary operators
. . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Boolean values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Undefined values
. . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Automatic type conversion
. . . . . . . . . . . . . . . . . . . . . 19
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2 Program Structure
23
Expressions and statements
. . . . . . . . . . . . . . . . . . . . 23
Variables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Keywords and reserved words
. . . . . . . . . . . . . . . . . . . 26
The environment
. . . . . . . . . . . . . . . . . . . . . . . . . . 27
Functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
The console.log function
. . . . . . . . . . . . . . . . . . . . . . 28
Return values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
prompt and confirm
. . . . . . . . . . . . . . . . . . . . . . . . . 29
Control flow
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Conditional execution
. . . . . . . . . . . . . . . . . . . . . . . . 30
while and do loops
. . . . . . . . . . . . . . . . . . . . . . . . . . 32
Indenting Code
. . . . . . . . . . . . . . . . . . . . . . . . . . . 34
ii
for loops
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Breaking Out of a Loop
. . . . . . . . . . . . . . . . . . . . . . 36
Updating variables succinctly
. . . . . . . . . . . . . . . . . . . 36
Dispatching on a value with switch
. . . . . . . . . . . . . . . . 37
Capitalization
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Comments
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Exercises
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3 Functions
42
Defining a function
. . . . . . . . . . . . . . . . . . . . . . . . . 42
Parameters and scopes
. . . . . . . . . . . . . . . . . . . . . . . 43
Nested scope
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Functions as values
. . . . . . . . . . . . . . . . . . . . . . . . . 46
Declaration notation
. . . . . . . . . . . . . . . . . . . . . . . . 47
The call stack
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Optional Arguments
. . . . . . . . . . . . . . . . . . . . . . . . . 49
Closure
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Recursion
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Growing functions
. . . . . . . . . . . . . . . . . . . . . . . . . . 55
Functions and side effects
. . . . . . . . . . . . . . . . . . . . . 58
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Exercises
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4 Data Structures: Objects and Arrays
61
The weresquirrel
. . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Data sets
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Properties
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Methods
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Objects
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Mutability
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
The lycanthrope’s log
. . . . . . . . . . . . . . . . . . . . . . . . 69
Computing correlation
. . . . . . . . . . . . . . . . . . . . . . . 71
Objects as maps
. . . . . . . . . . . . . . . . . . . . . . . . . . . 73
The final analysis
. . . . . . . . . . . . . . . . . . . . . . . . . . 74
Further arrayology
. . . . . . . . . . . . . . . . . . . . . . . . . . 76
Strings and their properties
. . . . . . . . . . . . . . . . . . . . 78
iii
Marijn Haverbeke