Underhanded JavaScript
$19.77
Minimum price
$27.60
Suggested price

Underhanded JavaScript

How To Be A Complete Arsehole with Bad JavaScript

About the Book

"WTF, JavaScript! Curse you Eich! Damn you Crockford!! JavaScript is the worst language ever!"

Ever had those moments when reading someone else's JavaScript code and screamed something like the above? Code that appears to do one thing but actually does something else? Welcome to the weird and wonderful world of JavaScript.

JavaScript can be a beautiful language - there exists a book about 100 pages on the good parts of JavaScript after all. However it's more often than not more full of warts. The problem is JavaScript does not follow the principle of least surprise. There are JavaScript code out there that can surprise even the most experienced of JavaScript developers - not in a good way,  mind. Accidental globals are just the tip of the iceberg.

If you have ever seen WTF-worthy JavaScript code (and any JavaScript dev worth her salt would have encountered at least one) and wondered wtf is happening, this book is for you.

If you were surpised with the result of a particular piece of code, and wondered why the results are what they are, this book is for you.

If you have ever wondered why [0] == 0? Why "true" == true returns false then this book is for you.

In this book I go through ~12 examples of crazy JavaScript that would make anyone go "WTF??!", examples such as:

  • Why certain Immediately Invoked Function Expressions don't work?
  • Why in some contexts, commas act funnily.
  • Why in some cases newlines act funnily.
  • Why in some cases, Google Chrome appears to support block-level scoping without ES6 syntax
  • Why truthy values are not true, and why falsey values are not false
  • Why is eval evil?
  • What is foo)(
  • And many more

I go through these examples, and then explain how the examples happen and work, in a step-by-step manner. Then in a tongue-in-cheek manner, suggest ways to wreak havoc on the unsuspecting using said "quirks" of JavaScript. I for one do not actually condone such behaviour. However, all the examples in this book, I have actually seen in real life, and have often cursed the arsehole developers who wrote them. The actual main aim of this book is to help write better code by showing the obvious pitfalls that you may find when debugging other peoples' codes.

Sometimes, it's not that these developers are intentionally being arseholes. Most times, the code is well-intentioned, but due to the way the language (and/or implementation) works, the results come out unexpectedly. Other times, it is exceedingly intentional, and innocent-looking code can do a lot of (financial) damage. I cover these and more in the book.

If you want to know more about the content, here is a talk I gave about arsehole JavaScript

Who this Book Is For

This book assumes you are already an intermediate-to-advanced frontend or backend Javascript developer, and is considered to be light reading. Early reviews have compared it to a light-hearted Programmng Pearls for Javascript developers. This author thinks it's more like Programming Turds, but okay.

Current Status

The book is currently in final editing stages. No more new content will be added in the near future.

About the Author

Xuanyi Chew
Xuanyi Chew

Xuanyi actually wrote this book while procrastinating on another much larger book on Javascript virtual machines (also Hacker News was down). The inspiration for this book was derived from all the times he was driven crazy by bad and downright bizzare Javascript code. He decided to catalogue those quirks and write up explanations as to why they happen.

Other than that, Xuanyi, like Zaphod Beeblebrox, is just this guy, you know...

Bundles that include this book

$56.79
Bought separately
$29.58
Bundle Price

Table of Contents

    • Introduction
    • How To Read This Book
      • The Tone
      • The Layout
      • The Formatting
    • Weird IIFE Behaviour
      • The Explanation
      • Exceptions
      • How to Be A Complete Arsehole
    • The Comma Trick
      • The Explanation
      • Miscelleny
      • How to Be A Complete Arsehole
    • Block Scoping Without ES6/Harmony
      • The Explanation
      • How to Be A Complete Arsehole
    • What’s True is True. What’s False is True
      • The Explanation
      • Exceptions
      • How to Be A Complete Arsehole
    • Automatic Schmautomatic
      • The Explanation
      • The Value of Using Crockford-style IIFE Declarations
      • How to Be A Complete Arsehole
    • Many (Un)Happy Returns this new Object
      • The Explanation
      • How to Be A Complete Arsehole
    • Extending the Fun
      • The Explanation
      • How to Be A Complete Arsehole
    • Float Like A Butterfly, Sting Like A Bee
      • The Explanation
      • How To Be A Complete Arsehole
    • Now You Have Two Problems
      • The Explanation
      • How To Be A Complete Arsehole
    • Unprecedented Conditions
      • The Explanation
      • How To Be A Complete Arsehole
    • Accidentally Went Global
      • The Explanation
      • How To Be A Complete Arsehole
    • Eviluating Functions
      • The Explanation
      • How To Be A Complete Arsehole
    • General Rules of Being a Complete Arsehole
      • Rule 1: Be Selfish
      • Rule 2: The Principle of Most Surprise
      • Rule 3: Theatre
  • Bonus Material
    • Browser Secrets
      • Base64 Encoding
      • Hidden Selectors
      • HTML Can Be Executed as JavaScript
      • Deleting Certain window Properties For Security
    • Miscellenous
      • Break and Switch
      • There is null Spoon
      • Nulls Are Strings Too
      • Don’t Declare Object Literals
      • Elided Array Elements Are Not Defined
      • Radix in parseInt
      • Typed Arrays Mess With Other Peoples’ Expectations
    • What Every JavaScript Developer Should Know About Floating Points
      • Floating Points
      • The Radix Point
      • Removing the Radix Point
      • IEEE 754
      • Rounding Errors
      • Handling Floating Points in JavaScript

Causes Supported

Electronic Frontier Foundation

Defending your civil liberties in a digital world.
https://www.eff.org/

Based in San Francisco, EFF is a donor-supported membership organization working to protect fundamental rights regardless of technology.

From the Internet to the iPod, technologies are transforming our society and empowering us as speakers, citizens, creators, and consumers. When our freedoms in the networked world come under attack, the Electronic Frontier Foundation (EFF) is the first line of defense. EFF broke new ground when it was founded in 1990—well before the Internet was on most people's radar—and continues to confront cutting-edge issues defending free speech, privacy, innovation, and consumer rights today. From the beginning, EFF has championed the public interest in every critical battle affecting digital rights.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub