Categories
Software Engineering

Anatomy of a programming language

(WP)

Sources:

Fair Use Sources:

Categories
Bibliography JavaScript Software Engineering

The Joy of JavaScript, by Luis Atencio

See also: JavaScript Bibliography and Bibliography of JavaScript Libraries and Web Frameworks

See: The Joy of JavaScript, by Luis Atencio, 2021, 1617295868 (TJoJ)

Fair Use Source: 1617295868 (TJoJ)

About This Book:

About the Author:

Book Details:

  • ISBN-10: 1617295868
  • ISBN-13: 978-161729586
  • Publisher: Manning Publications; 1st edition (May 12, 2020)
  • Paperback: 325 pages

Table of Contents:

Brief Contents:

1 JavaScript Reloaded

Part 1: Objects

2 Prototype-based object models

3 Delegation-based, compositional object models

Part 2: Functions

4 Pure, composable functions

5 Higher-kinded composition

Part 3: Code

6 ECMAScript Modules

7 Hooked on metaprogramming

Part 4: Data

8 Linear async flows

9 Streams programming

Appendix

A Babel configuration

B Typed JavaScript

1 JavaScript Reloaded

This chapter covers:

· Evaluating the key aspects of day-to-day coding: objects, functions, code, and data

· Comparing prototype-based and delegation-based object models

· Composability of functions and types

· Achieving clear separation of concerns through modularity and meta-programming

· Using promises and streams programming to create unidirectional data pipelines

· Introducing the sample blockchain application

“Any application that can be written in JavaScript, will eventually be written in JavaScript”

Jeff Atwood

It’s an amazing time to be a JavaScript developer. Today, JavaScript developers can write code that runs virtually anywhere from tablets, smartphones, desktops, bots, cloud platforms, to Internet of Things, such as toasters, refrigerators, thermostats, and even spacesuits! Also, we can program all tiers of an application stack, from the client and server, all the way down to the database. The world is at our fingertips.

Despite JavaScript’s resounding popularity, most developers—even those who use it every day–still struggle to decide how to approach writing a new application. Most of the time, you or your organization will have a prearranged framework of choice, and that gives you a good starting point. But even in these situations, frameworks only get you so far; business domain logic (done in plain JavaScript coding) will always be the most difficult and uncertain parts of the equation—one that you can’t just throw a library at to get it done. For these cases, it’s important you have a good grasp of the language’s syntax, the features it has to offer, and the paradigms it supports.

With most general-purpose programming languages, there’s typically a recommended way of solving a certain type of problem. With JavaScript, however, there tends to be twice this amount. The reason for this is that JavaScript glues the web together, not just in browsers and mobile devices, but also increasingly more in the server. Hence, it’s evolving to meet the demands and rise to the new challenges imposed by both of these (sometimes opposite) environments. Examples of some of these challenges are managing asynchronous data, breaking apart complex parts of your business logic in simple, maintainable modules. We now need to use JavaScript to, for instance, instantiate objects with proper abstractions that match our way of reasoning; decompose complex algorithms; modularize code for optimal reusability; and handle (potentially infinite) streams of data. And, to top it off, all of this requires good design skills so that code is simple to reason about and easy to maintain.

That is where The Joy of JavaScript comes in. The goal of this book is to help you identify and work with the different features the language provides so that you become a well-rounded JavaScript professional with an understanding of how expert developers are using it. The breadth of topics covered will give you enough information so that you can focus and master what you, in particular, need to tackle today’s and tomorrow’s challenges. It will also prepare you to use some of the new features coming into the language any day now, including pipeline and bind operators, throw expressions, observables, and more. My aim is to make you a better, more productive programmer so that you can do more with less. After just a few chapters—and certainly by the end of the book—you should be writing even leaner and more elegant code than you are already writing. In short, you’ll emerge from this book with a batch of new tools and techniques at your disposal for more effective and efficient programming, whether you are writing code for the front-end or the back-end.

Many years back, JavaScript development wasn’t particularly associated with “joy.” It was cumbersome to manage deep object hierarchies, for example, or to package your application into modules that would work across environments. The problem of implementing cross-platform, cross-vendor compatible code, plus the lack of tool support, made lots of developers cringe at the idea of having to write or maintain JavaScript code for a living. But that’s changing.

Thankfully, we’re now in the modern days of JavaScript development, which means several things. First, we can now closely monitor JavaScript’s steady evolution with a well-defined, fast-paced, task group called TC39 that pushes new language features every year, all in the open and transparently. This creates both excitement and angst because it inevitable forces you to rethink or throw away old habits and get ready for what’s coming ahead. Not all developers embrace change well or keep an open mind, but I hope you do.

Secondly, the days of copy-paste programming are long behind us, and with it the stigma brought by having “Script” in the name as somehow describing an inferior language. This was a global sentiment many years ago, and it’s no longer the case. The JavaScript ecosystem is amongst the most vibrant and cutting-edge, and today JavaScript developers rank amongst the top paid in the industry.

Finally, the misconception that a JavaScript developer is a jQuery, React, Angular, Vue, Svelte, or a developer is fading. You’re a JavaScript developer—period. The decision to use any of these frameworks or libraries is yours to make, only if you need it. By using good practices and learning how to properly utilize the wide spectrum of tools that JavaScript gives you, plain, vanilla JavaScript is powerful enough let your creativity run wild and contribute to any kind of project.

To bring you into the present and future of JavaScript programming, this book explores the language in the context of the most popular paradigms—functional, reflective, and reactive—and how to work with key coding components within each paradigm. The book is organized around the four themes used in addressing most programming problems: objects, functions, code, and data. Within these themes you’ll learn proper object models to use to design your business domain, how to combine functions and transform these objects into the desired output, how to effectively modularize your application, and finally how to manage the data that flows through your application, whether it’s synchronous or asynchronous.

As you can see from the spectrum of topics covered, this book is not for a JavaScript newcomer or beginner. This book assumes you already have some professional experience and a strong grasp of the basics like variables, loops, objects, functions, scopes, and closures, and have gone through the exercise of implementing and configuring JavaScript programs and setting up a transpiler like Babel or TypeScript.

Modern JavaScript development is only possible when the language has a consistent, steady evolution of features and syntax changes that that aims at tackling these modern problems.

1.1 Evolving JavaScript

For many years the evolution of JavaScript had been stagnant. To put it in perspective, ECMAScript, the specification language for JavaScript, had been stuck at version 3.1 across major JavaScript engines since December of 2009. This version was later renamed to the better-known ECMAScript 5 or ES5. We waited for nearly six years –June 2015 to be exact—to see any progress made to the language. In tech-years this is a very long time, even ATM machines get updated sooner.

During this team time, a standards committee known as TC39 (https://github.com/tc39), with the help of other institutions such as OpenJS foundation (https://openjsf.org/), gives birth to ECMAScript 2015 (also known as ES6). This was the biggest leap of change that JavaScript had ever seen since its inception. Amongst the most important features in this release were: classes, arrow functions, promises, template literals, blocked-scoped variables, default arguments, meta-programming support, destructuring assignment, modules, and many others (http://es6-features.org). Aside from all of these most-needed language features, the most important change is that JavaScript’s evolution has now shifted to a yearly release cadence. This allows the language to iterate quickly and address problems and shortcomings sooner. To help you keep track of where we’re at ES6 refers to ECMAScript 2015, ES7 to ECMAScript 2016, and so on. These incremental releases are much easier to adopt and manage by platform vendors, rather than monolithic releases.

TC39 is composed from members of leading web companies that will also continue evolving ECMAScript, the specification language set to standardize JavaScript, known internationally as ISO/IEC 16262 or ECMA262, for short. Lots of acronyms, I know, but hopefully you got the gist of it all. TC39 is also a platform for the whole community to have some input into where the language is headed through participation in IRC channels, mailing lists, as well as helping document and finding issues in existing proposals. If you take a quick look at the language proposals in their GitHub site you can identify that each one goes through a set of stages. These are well documented there, so I’ll just summarize them for you:

· Stage 0 (Strawman): this stage is informal and the proposal can have any form; it allows anyone to contribute into the further development of the language. To add your input, you must be either a member of TC39 or registered with ECMA International. If you’re interested, feel free to register at https://tc39.github.io/agreements/contributor. Once registered you can propose your idea via the es-discuss mailing list. You can also follow the discussions at https://esdiscuss.org/.

· Stage 1 (Proposal): after a strawman has been made, a member of TC39 must champion your addition to advance it to the next stage. This means the TC39 member must explain why the addition is useful and describe how it will behave and look once implemented.

· Stage 2 (Draft): then the proposal gets fully spec’d out and is considered experimental. If it reaches this stage, it means the committee expects the feature to eventually make it into the language.

· Stage 3 (Candidate): at this stage, the solution is considered complete and is signed-off. Changes after this stage are rare, and are generally only for critical discoveries after implementation and significant usage. You can feel comfortable using features in this stage. After a suitable period of deployment, the addition is safely bumped to stage 4.

· Stage 4 (Finished): this is the final stage; if a proposal reaches this stage it is ready to be included in the formal ECMAScript standard specification.

This healthy evolution and affluence of new proposals is important so that JavaScript keeps up with the demands of today’s application development practices. Aside from the cool techniques and paradigms that come alive only with JavaScript, this book also introduces you to a few proposals that will forever change how we write JavaScript in the near future. Some of which I’ll briefly mention in this chapter. Here they are in the order they’ll appear in the rest of the book:

· Private class fields (https://github.com/tc39/proposal-class-fields) allows you to define access modifiers (private, static) to a class’s properties.

· Pipeline operator (https://github.com/tc39/proposal-pipeline-operator) brings the Unix-like pipe feature of functional languages to JavaScript functions.

· Bind operator (https://github.com/tc39/proposal-bind-operator) is a new language syntax that abstract use of Function.prototype.bind.

· Throw expressions (https://github.com/tc39/proposal-throw-expressions) allows you to treat a throw statement as if it were a function or a variable.

· Observables (https://github.com/tc39/proposal-observable) enable the stream-based, reactive paradigm.

For most of the remainder if this chapter, I’ll introduce you to the book’s four major themes, so you can have an understanding of the big picture, and how the themes build up relate to each other, starting with objects.

Sources:

Fair Use Sources:

Categories
Bibliography

1617295868

See: The Joy of JavaScript, by Luis Atencio, 2021

Fair Use Source: 1617295868 (TJoJ)

Categories
Bibliography JavaScript Software Engineering

You Don’t Know JS: ES6 and Beyond, (YDKJS) JavaScript Book 6, 1st edition, by Kyle Simpson, 2015

See also: JavaScript, You Don’t Know JS Yet (YDKJSY) JavaScript Book Series by Kyle Simpson, JavaScript Bibliography and Bibliography of JavaScript Libraries and Web Frameworks

See: You Don’t Know JS: ES6 and Beyond, (YDKJS), JavaScript Book 6, 1st edition, by Kyle Simpson, 2015, 1491904240 (YDKJS-6)

Fair Use Source: 1491904240 (YDKJS-6)

Read free here: https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/es6%20&%20beyond/README.md#you-dont-know-js-es6–beyond

Buy here https://leanpub.com/p/getipub rather than Kyle’s Amazon page or his Amazon 2nd edition book series page.

About This Book:

No matter how much experience you have with JavaScript, odds are you don’t fully understand the language. As part of the “You Don’t Know JS” series, this compact guide focuses on new features available in ECMAScript 6 (ES6), the latest version of the standard upon which JavaScript is built.

Like other books in this series, You Don’t Know JS: ES6 & Beyond dives into trickier parts of the language that many JavaScript programmers either avoid or know nothing about. Armed with this knowledge, you can achieve true JavaScript mastery.

With this book, you will:

  • Learn new ES6 syntax that eases the pain points of common programming idioms
  • Organize code with iterators, generators, modules, and classes
  • Express async flow control with Promises combined with generators
  • Use collections to work more efficiently with data in structured ways
  • Leverage new API helpers, including Array, Object, Math, Number, and String
  • Extend your program’s capabilities through meta programming
  • Preview features likely coming to JS beyond ES6

About the Author:

Kyle Simpson is an Open Web evangelist from Austin, Texas, who’s passionate about all things JavaScript. He’s an author, workshop trainer, tech speaker, and OSS contributor/leader. https://github.com/getify, https://linkedin.com/in/getify

Kyle Simpson

Book Details:

  • ASIN: 1491904240
  • ISBN-10: 9781491904244
  • ISBN-13: 978-1491904244
  • Publisher : O’Reilly Media; 1st edition (January 12, 2016) — 2nd edition published by GetiPub (http://getipub.com), a division of Getify Solutions, Inc., and produced by Leanpub (https://leanpub.com/p/getipub).
  • Paperback : 278 pages

Table of Contents:

Sources:

Fair Use Sources:

Categories
Bibliography

1491904240

See: You Don’t Know JS: ES6 and Beyond, (YDKJS), JavaScript Book 6, 1st edition, by Kyle Simpson, 2015

Fair Use Source: 1491904240 (YDKJS-6)

Categories
Bibliography JavaScript Software Engineering

You Don’t Know JS: Async & Performance, (YDKJS) JavaScript Book 5, 1st edition, by Kyle Simpson, 2015

See also: JavaScript, You Don’t Know JS Yet (YDKJSY) JavaScript Book Series by Kyle Simpson, JavaScript Bibliography and Bibliography of JavaScript Libraries and Web Frameworks

See: You Don’t Know JS: Async & Performance, (YDKJS), JavaScript Book 5, 1st edition, by Kyle Simpson, 2015, 1491904224 (YDKJS-5)

Fair Use Source: 1491904224 (YDKJS-5)

Read free here: https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/async%20&%20performance/README.md#you-dont-know-js-async–performance

Buy here https://leanpub.com/p/getipub rather than Kyle’s Amazon page or his Amazon 2nd edition book series page.

About This Book:

No matter how much experience you have with JavaScript, odds are you don’t fully understand the language. As part of the “You Don’t Know JS” series, this concise yet in-depth guide focuses on new asynchronous features and performance techniques—including Promises, generators, and Web Workers—that let you create sophisticated single-page web applications and escape callback hell in the process.

Like other books in this series, You Don’t Know JS: Async & Performance dives into trickier parts of the language that many JavaScript programmers simply avoid. Armed with this knowledge, you can become a true JavaScript master.

With this book you will:

  • Explore old and new JavaScript methods for handling asynchronous programming
  • Understand how callbacks let third parties control your program’s execution
  • Address the “inversion of control” issue with JavaScript Promises
  • Use generators to express async flow in a sequential, synchronous-looking fashion
  • Tackle program-level performance with Web Workers, SIMD, and asm.js
  • Learn valuable resources and techniques for benchmarking and tuning your expressions and statements

About the Author:

Kyle Simpson is an Open Web evangelist from Austin, Texas, who’s passionate about all things JavaScript. He’s an author, workshop trainer, tech speaker, and OSS contributor/leader. https://github.com/getify, https://linkedin.com/in/getify

Kyle Simpson

Book Details:

  • ASIN: 1491904224
  • ISBN-10: 9781491904220
  • ISBN-13: 978-1491904220
  • Publisher : O’Reilly Media; 1st edition (March 24, 2015) – 2nd edition published by GetiPub (http://getipub.com), a division of Getify Solutions, Inc., and produced by Leanpub (https://leanpub.com/p/getipub).
  • Paperback : 296 pages

Table of Contents:

Sources:

Fair Use Sources:

Categories
Bibliography

1491904224

See: You Don’t Know JS: Async & Performance, (YDKJS), JavaScript Book 5, 1st edition, by Kyle Simpson, 2015

Fair Use Source: 1491904224 (YDKJS-5)

Categories
Bibliography JavaScript Software Engineering

You Don’t Know JS: Types & Grammar, (YDKJS) JavaScript Book 4), 1st edition, by Kyle Simpson, 2015

See also: JavaScript, You Don’t Know JS Yet (YDKJSY) JavaScript Book Series by Kyle Simpson, JavaScript Bibliography and Bibliography of JavaScript Libraries and Web Frameworks

See: You Don’t Know JS: Types & Grammar, (YDKJS), JavaScript Book 4, 1st edition, by Kyle Simpson, 2015, 1491904194 (YDKJS-4)

Fair Use Source: 1491904194 (YDKJS-4)

Read free here: https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/types%20&%20grammar/README.md#you-dont-know-js-types–grammar

Buy here https://leanpub.com/p/getipub rather than Kyle’s Amazon page or his Amazon 2nd edition book series page.

About This Book:

No matter how much experience you have with JavaScript, odds are you don’t fully understand the language. As part of the “You Don’t Know JS” series, this compact guide explores JavaScript types in greater depth than previous treatments by looking at type coercion problems, demonstrating why types work, and showing you how to take advantage of these features.

Like other books in this series, You Don’t Know JS: Types & Grammar dives into trickier parts of the language that many JavaScript programmers simply avoid or assume don’t exist (like types). Armed with this knowledge, you can achieve true JavaScript mastery.

With this book you will:

  • Get acquainted with JavaScript’s seven types: null, undefined, boolean, number, string, object, and symbol
  • Understand why JavaScript’s unique array, string, and number characteristics may delight or confound you
  • Learn how natives provide object wrappers around primitive values
  • Dive into the coercion controversy—and learn why this feature is useful in many cases
  • Explore various nuances in JavaScript syntax, involving statements, expressions, and other features

About the Author:

Kyle Simpson is an Open Web evangelist from Austin, Texas, who’s passionate about all things JavaScript. He’s an author, workshop trainer, tech speaker, and OSS contributor/leader. https://github.com/getify, https://linkedin.com/in/getify

Kyle Simpson

Book Details:

  • ASIN: 1491904194
  • ISBN-10: 9781491904190
  • ISBN-13: 978-1491904190
  • Publisher: O’Reilly Media; 1st edition (February 24, 2015) — 2nd edition published by GetiPub (http://getipub.com), a division of Getify Solutions, Inc., and produced by Leanpub (https://leanpub.com/p/getipub).
  • Paperback : 198 pages

Table of Contents:

Table of Contents

Sources:

Fair Use Sources:

Categories
Bibliography

1491904194

See: You Don’t Know JS: Types & Grammar, (YDKJS), JavaScript Book 4, 1st edition, by Kyle Simpson, 2015

Fair Use Source: 1491904194 (YDKJS-4)

Categories
Bibliography JavaScript Software Engineering

You Don’t Know JS: this & Object Prototypes, (YDKJS) JavaScript Book 3), 1st edition by Kyle Simpson, 2015

See also: JavaScript, You Don’t Know JS Yet (YDKJSY) JavaScript Book Series by Kyle Simpson, JavaScript Bibliography and Bibliography of JavaScript Libraries and Web Frameworks

See: You Don’t Know JS: this & Object Prototypes, (YDKJS), JavaScript Book 3, 1st edition, by Kyle Simpson, 2015, 1491904151 (YDKJS-3)

Fair Use Source: 1491904151 (YDKJS-3)

Read free here: https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/this%20&%20object%20prototypes/README.md#you-dont-know-js-this–object-prototypes

Buy here https://leanpub.com/p/getipub rather than Kyle’s Amazon page or his Amazon 2nd edition book series page.

About This Book:

No matter how much experience you have with JavaScript, odds are you don’t fully understand the language. This concise, in-depth guide takes you inside JavaScript’s this structure and object prototypes. You’ll learn how they work and why they’re integral to behavior delegation—a design pattern in which objects are linked, rather than cloned.

Like other books in the “You Don’t Know JS” series, this and Object Prototypes dives into trickier parts of the language that many JavaScript programmers simply avoid. Armed with this knowledge, you can become a true JavaScript master.

With this book you will:

  • Explore how the this binding points to objects based on how the function is called
  • Look into the nature of JS objects and why you’d need to point to them
  • Learn how developers use the mixin pattern to fake classes in JS
  • Examine how JS’s prototype mechanism forms links between objects
  • Learn how to move from class/inheritance design to behavior delegation
  • Understand how the OLOO (objects-linked-to-other-objects) coding style naturally implements behavior delegation

About the Author:

Kyle Simpson is an Open Web evangelist from Austin, Texas, who’s passionate about all things JavaScript. He’s an author, workshop trainer, tech speaker, and OSS contributor/leader. https://github.com/getify, https://linkedin.com/in/getify

Kyle Simpson

Book Details:

  • ASIN: 1491904151
  • ISBN-10: 9781491904152
  • ISBN-13: 978-1491904152
  • Publisher: O’Reilly Media; 1st edition (August 12, 2014) – 2nd edition published by GetiPub (http://getipub.com), a division of Getify Solutions, Inc., and produced by Leanpub (https://leanpub.com/p/getipub).
  • Paperback: 174 pages

Table of Contents:

Table of Contents

Sources:

Fair Use Sources:

Categories
Bibliography

1491904151

See: You Don’t Know JS: this & Object Prototypes, (YDKJS), JavaScript Book 3, 1st edition, by Kyle Simpson, 2015

Fair Use Source: 1491904151 (YDKJS-3)

Categories
Bibliography JavaScript Software Engineering

You Don’t Know JS: Up & Going (YDKJS), JavaScript Book 1, 1st edition, by Kyle Simpson, 2015

See also: JavaScript, You Don’t Know JS Yet (YDKJSY) JavaScript Book Series by Kyle Simpson, JavaScript Bibliography and Bibliography of JavaScript Libraries and Web Frameworks

You Don’t Know JS: Up & Going, (YDKJSY), JavaScript Book 1, 1st edition, by Kyle Simpson, 2015, 1491924462 (YDKJS-1)

The new version is You Don’t Know JS Yet: Get Started (YDKJSY), JavaScript Book 1, 2nd edition, by Kyle Simpson, 2020, B084BNMN7T (YDKJSY-1)

Fair Use Source: 1491924462 (YDKJS-1)

Buy here https://leanpub.com/p/getipub rather than Kyle’s Amazon page or his Amazon 2nd edition book series page.

About This Book:

About the Author:

Kyle Simpson is an Open Web evangelist from Austin, Texas, who’s passionate about all things JavaScript. He’s an author, workshop trainer, tech speaker, and OSS contributor/leader. https://github.com/getify, https://linkedin.com/in/getify

Kyle Simpson

Book Details:

Table of Contents:

Sources:

Fair Use Sources:

License & Copyright:

© 2013-2019 Kyle Simpson. This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Unported License.

Categories
Bibliography

1491924462

See: You Don’t Know JS: Up & Going, (YDKJS), JavaScript Book 1, 1st edition, by Kyle Simpson, 2015

Fair Use Source: 1491924462 (YDKJS-1)

Categories
Bibliography JavaScript Software Engineering

You Don’t Know JS Yet: Scope & Closures (YDKJSY JavaScript Book 2) by Kyle Simpson, 2020

See also: JavaScript, You Don’t Know JS Yet (YDKJSY) JavaScript Book Series by Kyle Simpson, JavaScript Bibliography and Bibliography of JavaScript Libraries and Web Frameworks

You Don’t Know JS Yet: Scope & Closures (YDKJSY), JavaScript Book 2, 2nd edition, by Kyle Simpson, 2020, B086GD45ZG (YDKJSY-2)

Fair Use Source: B086GD45ZG (YDKJSY-2)

Buy here https://leanpub.com/ydkjsy-scope-closures (https://leanpub.com/p/getipub) rather than Kyle’s Amazon page or his Amazon 2nd edition book series page.

About This Book:

Are you looking for a better way to deeply learn the fundamentals of JavaScript? Look no further!

The foundation of all programs is the organization of its variables and functions into different nested scopes. Yet, most developers haven’t deeply contemplated how and why these decisions are made and the impacts on code maintainability.

The worldwide best selling “You Don’t Know JS” book series is back for a 2nd edition: “You Don’t Know JS Yet”. All 6 books are brand new, rewritten to cover all sides of JS for 2020 and beyond.

“Scope & Closures” examines all aspects of lexical scope, then builds on these principles to leverage the power of closure, and finally digs into the module pattern for better program structure.

In Scope & Closures, you’ll dig into:

  • Nesting lexical scopes with functions and blocks, to limit scope exposure of variables
  • Functions remembering variables through closure
  • Modules, one of the most important code organization patterns in programming

About the Author:

Kyle Simpson is an Open Web evangelist from Austin, Texas, who’s passionate about all things JavaScript. He’s an author, workshop trainer, tech speaker, and OSS contributor/leader. https://github.com/getify, https://linkedin.com/in/getify

Kyle Simpson

Book Details:

  • ASIN: B08634PZ3N and B086GD45ZG
  • ISBN: 978-1-64786-226-8
  • Publisher: GetiPub & Leanpub; 2nd edition (March 17, 2020) – Published by GetiPub (http://getipub.com), a division of Getify Solutions, Inc., and produced by Leanpub (https://leanpub.com/p/getipub).
  • Publication date: March 17, 2020
  • Print length: 246 pages

Table of Contents:

  • Foreword
  • Preface
    • The Parts
    • The Title?
    • The Mission
    • The Path
  • Chapter 1: What’s the Scope?
    • About This Book
    • Compiled vs. Interpreted
    • Compiling Code
    • Compiler Speak
    • Cheating: Runtime Scope Modifications
    • Lexical Scope
  • Chapter 2: Illustrating Lexical Scope
    • Marbles, and Buckets, and Bubbles… Oh My!
    • A Conversation Among Friends
    • Nested Scope
    • Continue the Conversation
  • Chapter 3: The Scope Chain
    • “Lookup” Is (Mostly) Conceptual
    • Shadowing
    • Function Name Scope
    • Arrow Functions
    • Backing Out
  • Chapter 4: Around the Global Scope
    • Why Global Scope?
    • Where Exactly is this Global Scope?
    • Global This
    • Globally Aware
  • Chapter 5: The (Not So) Secret Lifecycle of Variables
    • When Can I Use a Variable?
    • Hoisting: Yet Another Metaphor
    • Re-declaration?
    • Uninitialized Variables (aka, TDZ)
    • Finally Initialized
  • Chapter 6: Limiting Scope Exposure
    • Least Exposure
    • Hiding in Plain (Function) Scope
    • Scoping with Blocks
    • Function Declarations in Blocks (FiB)
    • Blocked Over
  • Chapter 7: Using Closures
    • See the Closure
    • The Closure Lifecycle and Garbage Collection (GC)
    • An Alternative Perspective
    • Why Closure?
    • Closer to Closure
  • Chapter 8: The Module Pattern
    • Encapsulation and Least Exposure (POLE)
    • What Is a Module?
    • Node CommonJS Modules
    • Modern ES Modules (ESM)
    • Exit Scope
  • Appendix A: Exploring Further
    • Implied Scopes
    • Anonymous vs. Named Functions
    • Hoisting: Functions and Variables
    • The Case for var
    • What’s the Deal with TDZ?
    • Are Synchronous Callbacks Still Closures?
    • Classic Module Variations
  • Appendix B: Practice
    • Buckets of Marbles
    • Closure (PART 1)
    • Closure (PART 2)
    • Closure (PART 3)
    • Modules
    • Suggested Solutions
  • Notes

Dedication:

I must first thank my wife and kids, whose constant support is what allows me to keep going. I also want to thank the 500 original backers of the Kickstarter for “You Don’t Know JS” (1st ed), as well as the hundreds of thousands of folks who bought and read those books since. Without your financial support, this second edition wouldn’t be happening. Thanks also to the interviewer at a certain avian social media company who said I didn’t “know enough about JS”… you helped me name the series.

Next, I owe much of my current career path to Marc Grabanski and Frontend Masters. Marc took a chance on me and gave me my first shot at teaching years ago, and I wouldn’t have then become a writer had it not been for that! Frontend Masters is the Premier Sponsor of YDKJSY 2nd Edition. Thank you, Frontend Masters (and Marc).

Lastly, my editor, Simon St.Laurent, who helped me conceive the original YDKJS and was my first book editor. Simon’s support and guidance have profoundly impacted me and been an integral part of shaping me into the writer I am today. From those drinks we enjoyed at the Driskill all those years back, where YDKJS was born, through today, thank you so much Simon for shepherding and improving these books!

Foreword:

If I look over the books on my bookshelf, I can clearly see which of these titles are well loved. Well loved in this sense meaning they are a little worn. Their binding is broken, their pages are tattered, there might even be a spilled drink smear or two. What’s ironic to me is that the most loved of my books often look the least cared for, though honestly the opposite is true.

Scope and Closures (1st ed.) is one of my most loved books. It’s small, but the binding is coming undone. The pages are worn and dog-eared. It’s a bit rumpled. It’s not a book I’ve read once. I’ve picked it up again and again in the many years since it was originally published.

For me, it’s also been a benchmark for my own personal progression through JavaScript. When I first read it in 2014, I was familiar with the concepts but the depth of my understanding was admittedly not as deep as the thin volume.

Over the years, even though I wasn’t necessarily feeling my own improvement on a day-to-day basis, each one of the concepts became more approachable. I’d smile to myself, realizing how far I’d come with the help of these guides. It became apparent there was an inverse correlation between how well I treated the book and how much I loved it.

When Kyle asked me to write the Foreword for the 2nd edition, I was floored. It’s not often you’re asked to write about a book that’s been so formative for your own understanding and career, Scope and Closures in particular. I remember the day I first understood closures, the first time I used one well. The satisfaction was great, in part because the symmetry of the idea was compelling to me. Before I even picked this book up, I was already enamoured with closures. And yet, there’s a difference between being able to execute code successfully and fully explore the concepts with any depth. This book took my base understanding and drew it out, helped me master it.

This book is deceptively short. It’s helpful that it’s small because it’s dense with useful knowledge. Since it is compact, I’d suggest you give yourself time to absorb each page. Take your time with it. Treat the book with care, and by that I mean, wear it down.

~~

Sarah Drasner

Head of Developer Experience

Netlify

Preface:

Welcome to the 2nd edition of the widely acclaimed You Don’t Know JS (YDKJS) book series: You Don’t Know JS Yet (YDKJSY).

If you’ve read any of the 1st edition books, you can expect a refreshed approach in these new ones, with plenty of updated coverage of what’s changed in JS over the last five years. But what I hope and believe you’ll still get is the same commitment to respecting JS and digging into what really makes it tick.

If this is your first time reading these books, I’m glad you’re here. Prepare for a deep and extensive journey into all the corners of JavaScript.

If you are new to programming or JS, be aware that these books are not intended as a gentle “intro to JavaScript.” This material is, at times, complex and challenging, and goes much deeper than is typical for a first-time learner. You’re welcome here no matter what your background is, but these books are written assuming you’re already comfortable with JS and have at least 6–9 months experience with it.

The Parts:

These books approach JavaScript intentionally opposite of how The Good Parts treats the language. No, that doesn’t mean we’re looking at the bad parts, but rather, exploring all the parts.

You may have been told, or felt yourself, that JS is a deeply flawed language that was poorly designed and inconsistently implemented. Many have asserted that it’s the worst most popular language in the world; that nobody writes JS because they want to, only because they have to given its place at the center of the web. That’s a ridiculous, unhealthy, and wholly condescending claim.

Millions of developers write JavaScript every day, and many of them appreciate and respect the language.

Like any great language, it has its brilliant parts as well as its scars. Even the creator of JavaScript himself, Brendan Eich, laments some of those parts as mistakes. But he’s wrong: they weren’t mistakes at all. JS is what it is today—the world’s most ubiquitous and thus most influential programming language—precisely because of all those parts.

Don’t buy the lie that you should only learn and use a small collection of good parts while avoiding all the bad stuff. Don’t buy the “X is the new Y” snake oil, that some new feature of the language instantly relegates all usage of a previous feature as obsolete and ignorant. Don’t listen when someone says your code isn’t “modern” because it isn’t yet using a stage-0 feature that was only proposed a few weeks ago!

Every part of JS is useful. Some parts are more useful than others. Some parts require you to be more careful and intentional.

I find it absurd to try to be a truly effective JavaScript developer while only using a small sliver of what the language has to offer. Can you imagine a construction worker with a toolbox full of tools, who only uses their hammer and scoffs at the screwdriver or tape measure as inferior? That’s just silly.

My unreserved claim is that you should go about learning all parts of JavaScript, and where appropriate, use them! And if I may be so bold as to suggest: it’s time to discard any JS books that tell you otherwise.

The Title?

So what’s the title of the series all about?

I’m not trying to insult you with criticism about your current lack of knowledge or understanding of JavaScript. I’m not suggesting you can’t or won’t be able to learn JavaScript. I’m not boasting about secret advanced insider wisdom that I and only a select few possess.

Seriously, all those were real reactions to the original series title before folks even read the books. And they’re baseless.

The primary point of the title “You Don’t Know JS Yet” is to point out that most JS developers don’t take the time to really understand how the code that they write works. They know that it works—that it produces a desired outcome. But they either don’t understand exactly how, or worse, they have an inaccurate mental model for the how that falters on closer scrutiny.

I’m presenting a gentle but earnest challenge to you the reader, to set aside the assumptions you have about JS, and approach it with fresh eyes and an invigorated curiosity that leads you to ask why for every line of code you write. Why does it do what it does? Why is one way better or more appropriate than the other half-dozen ways you could have accomplished it? Why do all the “popular kids” say to do X with your code, but it turns out that Y might be a better choice?

I added “Yet” to the title, not only because it’s the second edition, but because ultimately I want these books to challenge you in a hopeful rather than discouraging way.

But let me be clear: I don’t think it’s possible to ever fully know JS. That’s not an achievement to be obtained, but a goal to strive after. You don’t finish knowing everything about JS, you just keep learning more and more as you spend more time with the language. And the deeper you go, the more you revisit what you knew before, and you re-learn it from that more experienced perspective.

I encourage you to adopt a mindset around JavaScript, and indeed all of software development, that you will never fully have mastered it, but that you can and should keep working to get closer to that end, a journey that will stretch for the entirety of your software development career, and beyond.

You can always know JS better than you currently do. That’s what I hope these YDKJSY books represent.

The Mission:

The case doesn’t really need to be made for why developers should take JS seriously—I think it’s already more than proven worthy of first-class status among the world’s programming languages.

But a different, more important case still needs to be made, and these books rise to that challenge.

I’ve taught more than 5,000 developers from teams and companies all over the world, in more than 25 countries on six continents. And what I’ve seen is that far too often, what counts is generally just the result of the program, not how the program is written or how/why it works.

My experience not only as a developer but in teaching many other developers tells me: you will always be more effective in your development work if you more completely understand how your code works than you are solely just getting it to produce a desired outcome.

In other words, good enough to work is not, and should not be, good enough.

All developers regularly struggle with some piece of code not working correctly, and they can’t figure out why. But far too often, JS developers will blame this on the language rather than admitting it’s their own understanding that is falling short. These books serve as both the question and answer: why did it do this, and here’s how to get it to do that instead.

My mission with YDKJSY is to empower every single JS developer to fully own the code they write, to understand it and to write with intention and clarity.

The Path:

Some of you have started reading this book with the goal of completing all six books, back to back.

I would like to caution you to consider changing that plan.

It is not my intention that YDKJSY be read straight through. The material in these books is dense, because JavaScript is powerful, sophisticated, and in parts rather complex. Nobody can really hope to download all this information to their brains in a single pass and retain any significant amount of it. That’s unreasonable, and it’s foolish to try.

My suggestion is you take your time going through YDKJSY. Take one chapter, read it completely through start to finish, and then go back and re-read it section by section. Stop in between each section, and practice the code or ideas from that section. For larger concepts, it probably is a good idea to expect to spend several days digesting, re-reading, practicing, then digesting some more.

You could spend a week or two on each chapter, and a month or two on each book, and a year or more on the whole series, and you would still not be squeezing every ounce of YDKJSY out.

Don’t binge these books; be patient and spread out your reading. Interleave reading with lots of practice on real code in your job or on projects you participate in. Wrestle with the opinions I’ve presented along the way, debate with others, and most of all, disagree with me! Run a study group or book club. Teach mini-workshops at your office. Write blog posts on what you’ve learned. Speak about these topics at local JS meetups.

It’s never my goal to convince you to agree with my opinion, but to encourage you to own and be able to defend your opinions. You can’t get there with an expedient read-through of these books. That’s something that takes a long while to emerge, little by little, as you study and ponder and re-visit.

These books are meant to be a field-guide on your wanderings through JavaScript, from wherever you currently are with the language, to a place of deeper understanding. And the deeper you understand JS, the more questions you will ask and the more you will have to explore! That’s what I find so exciting!

I’m so glad you’re embarking on this journey, and I am so honored you would consider and consult these books along the way. It’s time to start getting to know JS.

Sources:

Fair Use Sources:

License & Copyright:

© 2013-2019 Kyle Simpson. This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Unported License.

Categories
Bibliography

B086GD45ZG

See: You Don’t Know JS Yet: Scope & Closures (YDKJSY), JavaScript Book 2, 2nd edition, by Kyle Simpson, 2020

Fair Use Source: B086GD45ZG (YDKJSY-2)