How JavaScript Works
eBook - ePub

How JavaScript Works

Douglas Crockford

Share book
  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

How JavaScript Works

Douglas Crockford

Book details
Book preview
Table of contents
Citations

About This Book

A light-hearted romp thru the world’s most misunderstood programming language.

Douglas Crockford starts by looking at the fundamentals: names, numbers, booleans, characters, and bottom values. JavaScript’s number type is shown to be faulty and limiting, but then Crockford shows how to repair those problems. He then moves on to data structures and functions, exploring the underlying mechanisms and then uses higher order functions to achieve class-free object oriented programming.

The book also looks at eventual programming, testing, and purity, all the while looking at the requirements of The Next Language. Most of our languages are deeply rooted in the paradigm that produced FORTRAN. Crockford attacks those roots, liberating us to consider the next paradigm.

He also presents a strawman language and develops a complete transpiler to implement it. The book is deep, dense, full of code, and has moments when it is intentionally funny.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is How JavaScript Works an online PDF/ePUB?
Yes, you can access How JavaScript Works by Douglas Crockford in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation en JavaScript. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781949815023
How JavaScript Works
Douglas Crockford

Front Matter

Did I hear you right, did I hear you sayin’ that you’re gonna make a copy of a game without payin’? Come on, guys, I thought you knew better. Don’t copy that floppy.
MC Double Def DP
How JavaScript Works
Douglas Crockford
Copyright ©2018 Douglas Crockford
ISBN-13 978-1-94-981500-9 Paperback.
ISBN-13 978-1-94-981501-6 Hardcover.
ISBN-13 978-1-94-981502-3 EPUB.
The computer programs in this book are in the Public Domain. The programs are provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the author or publisher be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the programs or the use or other dealings in the programs. Please use the programs for good, not evil.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales which may include customized covers. For more information, please contact [email protected].
QA76.73.J39
005.2762

Chapter List

Raindrops on roses and whiskers on kittens.
Not Maria Augusta von Trapp
[ {"number": 0, "chapter": "Read Me First!"}, {"number": 1, "chapter": "How Names Work"}, {"number": 2, "chapter": "How Numbers Work"}, {"number": 3, "chapter": "How Big Integers Work"}, {"number": 4, "chapter": "How Big Floating Point Works"}, {"number": 5, "chapter": "How Big Rationals Work"}, {"number": 6, "chapter": "How Booleans Work"}, {"number": 7, "chapter": "How Arrays Work"}, {"number": 8, "chapter": "How Objects Work"}, {"number": 9, "chapter": "How Strings Work"}, {"number": 10, "chapter": "How Bottom Values Work"}, {"number": 11, "chapter": "How Statements Work"}, {"number": 12, "chapter": "How Functions Work"}, {"number": 13, "chapter": "How Generators Work"}, {"number": 14, "chapter": "How Exceptions Work"}, {"number": 15, "chapter": "How Programs Work"}, {"number": 16, "chapter": "How this Works"}, {"number": 17, "chapter": "How Class Free Works"}, {"number": 18, "chapter": "How Tail Calls Work"}, {"number": 19, "chapter": "How Purity Works"}, {"number": 20, "chapter": "How Eventual Programming Works"}, {"number": 21, "chapter": "How Date Works"}, {"number": 22, "chapter": "How JSON Works"}, {"number": 23, "chapter": "How Testing Works"}, {"number": 24, "chapter": "How Optimizing Works"}, {"number": 25, "chapter": "How Transpiling Works"}, {"number": 26, "chapter": "How Tokenizing Works"}, {"number": 27, "chapter": "How Parsing Works"}, {"number": 28, "chapter": "How Code Generation Works"}, {"number": 29, "chapter": "How Runtimes Work"}, {"number": 30, "chapter": "How Wat! Works"}, {"number": 31, "chapter": "How This Book Works"} ]

Chapter 0 Read Me First! ○○○○○

Few images invoke the mysteries and ultimate certainties of a sequence of random events as well as that of the proverbial monkey at a typewriter.
George Marsaglia
JavaScript is not very pretty, but it works.
This book is for people who have had some experience with JavaScript, and want to have a better, deeper understanding of how it works and how to use it well. It is also for experienced programmers who are looking to understand the workings of another language.
This book is not for beginners. I hope to someday write a book for beginners. This is not that book. This is not a light book. If you skim it, you will likely get nothing from it.
This book is not about JavaScript engines or virtual machines. It is about the language itself and the things every programmer should know about it. This book is a radical reappraisal of JavaScript, how it works, how it could be made better, and how it can be better used. It is about how to think about JavaScript and how to think in JavaScript. I am going to pretend that the current version of the language is the only version. I am not going to waste your time by showing how things worked in ES1 or ES3 or ES5. That does not matter. The focus is on how JavaScript works for us now.
This book is not comprehensive. There are large, complex chunks of the language that will be dismissed without a word. If I fail to mention your most favorite feature, that is most likely because that feature is crap. I will not be paying much attention to syntax. I am assuming that you already know how to write an if statement. If you need assistance with those sorts of details, ask JSLint. jslint.com
There are some useful parts of the language that I will spend little time on, such as most of the methods in the primordial prototypes. There are excellent online reference materials for that. My favorite resource is Mozilla Foundation.
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
An important goal in programming language design is to produce a clean, logical language that composes well and is free of weird corner cases. JavaScript came nowhere close to meeting that goal. It gets worse with each revision as more features are agglutinated. The language is full of weird corner and edge cases. This book illuminates only a few of those corners, just to show that there are monsters there. Stay away from the corners and edges. Do not go into the dark. Stay in the part of the language that is simple and clean. Everything you need to write good programs is there.
Ten years ago I wrote a cranky little pamphlet about JavaScript. The premise was unusual, that whilst JavaScript was obviously a mess, there was buried deep inside of it a very good language. By avoiding the bad parts, you could write good programs.
This was quite at odds with the opinion of some programming experts that mastery can only be demonstrated by exploiting all of a language’s features. They believed strongly, without any need of proof, that features exist for the demonstration of mastery, so there are no bad features.
That opinion still seems to dominate even though it is deeply wrong. True mastery is shown by writing good programs that are readable, maintainable, and free of error. If you ever feel the need to show off, try doing that. Being a humble programmer, I am always looking at myself and my work, seeking to improve my skills. I have learned the hard way that optimizing for feature exploitation is counterproductive.
This is my most powerful tool for improving a programming language:
If a feature is sometimes useful and sometimes dangerous and if there is a better option then always use the better option.
So armed, I am always looking to make the language I use smaller and better, to avoid if I can the features that are more likely to create bugs. I am still refining my ideas about what is good practice and what is not. This book represents my latest thinking about JavaScript. I am able to write about JavaScript’s good parts only becau...

Table of contents