Facebook Pixel
Searching...
English
EnglishEnglish
EspañolSpanish
简体中文Chinese
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
Bahasa IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Contre Bonne Fortune.

Contre Bonne Fortune.

by Guy De Rothschild 1983 372 pages
4.23
8k+ ratings
Listen

Key Takeaways

1. JavaScript's Good Parts: Embrace Simplicity and Power

JavaScript contains a large set of weak or problematic features that can undermine our attempts to write good programs. We should obviously avoid JavaScript's worst features.

Embrace the good, avoid the bad. JavaScript, despite its flaws, has a beautiful and powerful core. By focusing on its good parts, developers can create robust, efficient, and maintainable code. The language's flexibility allows for expressive and concise programming, but it also requires discipline to avoid its pitfalls.

Key good parts include:

  • Functions as first-class objects
  • Loose typing
  • Dynamic objects
  • Expressive object literal notation

Avoid problematic features such as:

  • Global variables
  • Implicit type coercion
  • The with statement
  • eval function

By carefully selecting which features to use, developers can harness JavaScript's power while minimizing risks and complexity.

2. Functions as First-Class Objects: The Heart of JavaScript

JavaScript's functions are first class objects with (mostly) lexical scoping. JavaScript is the first lambda language to go mainstream.

Functions are versatile and powerful. In JavaScript, functions are not just subroutines but full-fledged objects. This allows for incredible flexibility and expressiveness in programming. Functions can be assigned to variables, passed as arguments, returned from other functions, and even have properties and methods.

Key aspects of JavaScript functions:

  • Lexical scoping (closures)
  • Can be used to create modules
  • Support for functional programming patterns
  • Ability to create methods for objects

This feature enables powerful programming paradigms such as functional programming, object-oriented programming, and modular design. Mastering the use of functions is crucial for writing efficient and elegant JavaScript code.

3. Objects and Prototypes: Flexible and Efficient Inheritance

JavaScript has a class-free object system in which objects inherit properties directly from other objects. This is really powerful, but it is unfamiliar to classically trained programmers.

Prototypal inheritance is unique and powerful. JavaScript's object system is fundamentally different from class-based languages. Instead of classes, it uses prototypes for inheritance. This allows for more flexible and dynamic object relationships.

Key aspects of JavaScript's object system:

  • Objects can inherit directly from other objects
  • Dynamic addition of properties and methods
  • No need for class definitions
  • Efficient memory usage through prototype chain

While initially confusing for developers from class-based languages, embracing prototypal inheritance can lead to more flexible and efficient code. It allows for easy object creation, dynamic modification, and powerful patterns like object composition and delegation.

4. Avoid Global Variables: Enhance Code Quality and Security

The worst of all of JavaScript's bad features is its dependence on global variables.

Global variables are a major pitfall. The use of global variables in JavaScript can lead to numerous problems, including naming conflicts, security vulnerabilities, and difficulty in maintaining and debugging code. They make it challenging to create modular and reusable code.

Strategies to minimize global variables:

  • Use the module pattern
  • Employ closures to create private scopes
  • Utilize IIFE (Immediately Invoked Function Expressions)
  • Namespace your application under a single global object

By reducing the use of global variables, developers can create more robust, maintainable, and secure JavaScript applications. This practice also improves code organization and reduces the risk of unintended interactions between different parts of the program.

5. Understand and Leverage Closure for Powerful Programming

Functions in JavaScript form closures. A closure is the internal function plus the access to all the variables in external scopes.

Closures enable powerful patterns. Closure is a fundamental concept in JavaScript that allows functions to retain access to variables from their outer scope even after the outer function has returned. This enables powerful programming patterns and is key to many JavaScript design patterns.

Applications of closures:

  • Creating private variables and methods
  • Implementing the module pattern
  • Managing callbacks and asynchronous code
  • Creating function factories

Understanding and leveraging closures allows developers to write more efficient, secure, and modular code. It's a key concept for advanced JavaScript programming and is essential for creating sophisticated applications.

6. Embrace JSON for Data Interchange and Portability

JSON is a lightweight data interchange format. It is based on JavaScript's object literal notation, one of JavaScript's best parts.

JSON simplifies data exchange. JSON (JavaScript Object Notation) has become a standard for data interchange due to its simplicity, readability, and ease of use. It's language-independent but particularly well-suited for JavaScript applications.

Key benefits of JSON:

  • Lightweight and easy to read/write
  • Language-independent
  • Easy to parse and generate
  • Supports complex data structures

By using JSON for data interchange, developers can simplify communication between different parts of an application or between different systems. It's particularly useful in web applications for client-server communication and for storing configuration data.

7. Use JSLint to Enforce Best Practices and Catch Errors

JSLint is a JavaScript syntax checker and verifier. It takes a source text and scans it. If it finds a problem, it returns a message describing the problem and an approximate location within the source.

JSLint improves code quality. Using tools like JSLint can significantly improve the quality and consistency of JavaScript code. It helps enforce best practices, catch potential errors early, and maintain a high standard of code across a project or team.

Benefits of using JSLint:

  • Catches common programming errors
  • Enforces coding standards
  • Improves code readability and maintainability
  • Helps learn and adopt best practices

By integrating JSLint into the development process, teams can catch and fix issues early, leading to more robust and maintainable code. It's particularly valuable for large projects or teams where consistency is crucial.

8. Beware of JavaScript's Bad Parts: Navigate Pitfalls Wisely

JavaScript has lots of additional features that really don't add very much, and as you'll find in the appendixes that follow, it has a lot of features with negative value.

Avoid problematic features. While JavaScript has many powerful features, it also includes several problematic ones that can lead to bugs, security issues, or hard-to-maintain code. Knowing and avoiding these "bad parts" is crucial for writing robust JavaScript applications.

Key bad parts to avoid:

  • The with statement
  • eval function
  • Automatic semicolon insertion
  • typeof operator inconsistencies
  • == and != operators (use === and !== instead)

By being aware of these pitfalls and consciously avoiding them, developers can write cleaner, more reliable, and more maintainable JavaScript code. It's often better to use well-understood alternatives or workarounds for these problematic features.

Last updated:

Review Summary

4.23 out of 5
Average of 8k+ ratings from Goodreads and Amazon.

JavaScript: The Good Parts receives mixed reviews but is generally well-regarded. Readers appreciate its concise explanation of JavaScript's best features and its honest critique of the language's flaws. Many find it eye-opening and valuable for experienced programmers new to JavaScript. However, some criticize its organization, outdated information, and occasionally confusing explanations. The book's opinionated style and focus on best practices are praised by some but seen as overly dogmatic by others. Overall, it's considered an important read for serious JavaScript developers, despite its limitations.

Your rating:

About the Author

Douglas Crockford is a renowned figure in the world of JavaScript programming. He is best known for his work on JavaScript: The Good Parts, which has become a classic in the field. Crockford is credited with popularizing JSON (JavaScript Object Notation) and developing tools like JSLint. His strong opinions on JavaScript best practices have significantly influenced the language's development and usage. Crockford's expertise comes from years of experience working with JavaScript, and he is known for his straightforward, often critical approach to the language. His contributions have helped legitimize JavaScript as a serious programming language and have shaped how developers approach its use in modern web development.

Download PDF

To save this Contre Bonne Fortune. summary for later, download the free PDF. You can print it out, or read offline at your convenience.
Download PDF
File size: 0.72 MB     Pages: 11

Download EPUB

To read this Contre Bonne Fortune. summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.
Download EPUB
File size: 3.47 MB     Pages: 8
0:00
-0:00
1x
Dan
Andrew
Michelle
Lauren
Select Speed
1.0×
+
200 words per minute
Create a free account to unlock:
Bookmarks – save your favorite books
History – revisit books later
Ratings – rate books & see your ratings
Unlock unlimited listening
Your first week's on us!
Today: Get Instant Access
Listen to full summaries of 73,530 books. That's 12,000+ hours of audio!
Day 4: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 7: Your subscription begins
You'll be charged on Nov 22,
cancel anytime before.
Compare Features Free Pro
Read full text summaries
Summaries are free to read for everyone
Listen to summaries
12,000+ hours of audio
Unlimited Bookmarks
Free users are limited to 10
Unlimited History
Free users are limited to 10
What our users say
30,000+ readers
“...I can 10x the number of books I can read...”
“...exceptionally accurate, engaging, and beautifully presented...”
“...better than any amazon review when I'm making a book-buying decision...”
Save 62%
Yearly
$119.88 $44.99/yr
$3.75/mo
Monthly
$9.99/mo
Try Free & Unlock
7 days free, then $44.99/year. Cancel anytime.
Settings
Appearance