Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Ilya Kantor, javascript.info

Rating No ratings yet

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Javascript.info Ebook Part 1: The JavaScript Language ## 【One-Line Pitch】 A comprehensive, example-driven introduction to core JavaScript—from syntax basics to advanced object mechanics—ideal for beginners starting fresh and intermediate developers wanting to solidify their understanding of the language's foundations. ## 【Book Arc】 - **Opening (~0%–10%)**: Sets up the browser-based development environment, explains how to embed scripts with the `<script>` tag, and covers fundamental syntax—variables, data types, type conversions, and basic operators. This stage solves the "where do I start" problem for absolute beginners. - **Early (~10%–25%)**: Dives into control flow (conditionals, switch statements, loops), introduces functions as building blocks, and includes a humorous "ninja code" chapter on what *not* to do. Also covers modern practices like `"use strict"` and testing with BDD (Behavior-Driven Development). - **Early–Middle (~25%–40%)**: Explores objects in depth—property access, `this` binding, constructor functions with `new`, object-to-primitive conversion, and the nuances of copying vs. referencing. Introduces numbers (including hex/binary/octal notation) and strings with their methods. - **Middle (~40%–55%)**: Covers arrays and iterables thoroughly—array methods like `reduce`, `reduceRight`, and `Array.isArray`, plus the distinction between iterables and array-likes. Introduces `Map`, `Set`, `WeakMap`, and `WeakSet` for advanced data collection. - **Late (~55%–100%)**: Continues with destructuring assignment (arrays and objects), default values, and more advanced language features. The excerpts show a progression from simple syntax toward more sophisticated patterns and data structures. ## 【Key Takeaways】 - **Variables are your first building block** (Opening): JavaScript variable names allow letters, digits, `$`, and `_`, with camelCase as convention. Understanding naming rules and the `let` keyword prevents early confusion. (Early) - **Type conversion is explicit and sometimes surprising** (Opening): `Number("123")` converts strings to numbers, but invalid strings yield `NaN`. Conversion rules for `undefined`, `null`, and booleans are specific—know them to avoid bugs. (Early) - **The ternary operator and switch statements offer cleaner control flow** (Early): The `? :` operator handles simple conditionals, while `switch` supports grouping multiple cases and arbitrary expressions. Use them judiciously for readability. (Early) - **Functions are the main building blocks of scripts** (Early): The book emphasizes that functions go far beyond basics—they're revisited throughout with advanced features. Early exercises (like `checkAge`) teach refactoring between `if/else`, `?`, and `||` styles. (Early) - **Objects require understanding `this` binding** (Early–Middle): Using `user.name` inside a method breaks when the variable is reassigned; `this.name` works because `this` is bound at call time, not definition time. This is a classic JavaScript pitfall. (Middle) - **Object-to-primitive conversion follows a defined algorithm** (Middle): Three hints (`"string"`, `"number"`, `"default"`) determine whether `toString()` or `valueOf()` is called first. Implementing `toString()` alone often suffices for debugging and logging. (Middle) - **Arrays are objects, not a separate type** (Middle): `typeof []` returns `"object"`, so use `Array.isArray()` to distinguish arrays from plain objects. This matters for type-checking in real code. (Middle) - **`reduce` without an initial value is dangerous** (Middle): If the array is empty, `reduce` throws an error. Always specify an initial value to make code robust and predictable. (Middle) ## 【Reading Tips】 - **Skim the "ninja code" chapter** (around 19–23%): It's intentionally humorous and ironic, showing bad practices like confusing variable names. Read it for entertainment and as a cautionary tale, but don't memorize the "techniques." - **Deep-read the object and `this` sections** (around 29–32%): These are the most conceptually challenging parts. Work through the examples where `this` fails (like the `user = null` case) to internalize how binding works. - **Practice the exercises with sandboxes**: The book includes tasks with importance ratings (e.g., "Uppercase the first character" at importance 5). These are worth doing—they cement the concepts better than reading alone. - **Pay attention to the BDD/testing section** (around 23%): The `pow` function example shows how to write failing tests first, then implement. This is a valuable real-world skill, not just academic. - **Skim the string and number method lists**: You don't need to memorize every method. Note that `str.repeat(n)` and `e` notation exist, then look them up when needed. ## 【Coverage Limits】 This guide covers the first half of Part 1 (through destructuring and collections). The excerpts do not cover later topics like error handling, promises, async/await, generators, modules, or advanced function patterns—these appear in later sections of the book not included in this sample. ##
Excerpt 1
Scala or Erlang that forbid changing variable values. In such languages, once the value is stored “in the box”, it’s there forever. If we need to store ...
View in text
Excerpt 2
g still works, but some features behave in the old-fashion, “compatible” way. We’d generally prefer the modern behavior. Some modern features of the language...
View in text
Excerpt 3
milar objects, like multiple users or menu items and so on. That can be done using constructor functions and the "new" operator. Constructor function Constr...
View in text
Excerpt 4
actical tasks in browser or other environments, we may meet objects that are iterables or array-likes, or both. For instance, strings are both iterable ( for...
View in text
Excerpt 5
eachable, and keeps the outer lexical environment in memory Please note that if f() is called many times, and resulting functions are saved, then the corres...
View in text
Excerpt 6
te user.name // defineProperty(user, "name", ...) Object.defineProperty(user, "name", {writable: true}); // Error Object.defineProperties There’s a method...
View in text
Excerpt 7
JSON.parse(json); // <-- no errors if (!user.name) { throw new SyntaxError("Incomplete data: no name"); // (*) } alert( user.name ); } c...
View in text
Excerpt 8
Like this: fetch('/article/promise-chaining/user.json') .then(response => response.json()) .then(user => fetch(`https://api.github.com/users/${user.nam...
View in text
Tags
AI categories
JavaScriptProgramming LanguageProgramming
ISBN: 2019
Language: English
File Format: PDF
File Size: 7.3 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…