Goodreads helps you keep track of books you want to read.
Start by marking “You Don't Know JS: Scope and Closures (You Don't Know JS, #2)” as Want to Read:
You Don't Know JS: Scope and Closures (You Don't Know JS, #2)
Enlarge cover
Rate this book
Clear rating
Open Preview

You Don't Know JS: Scope and Closures

(You Don't Know JS #2)

4.55  ·  Rating details ·  1,623 ratings  ·  123 reviews
No matter how much experience you have with JavaScript, odds are you don't fully understand the language. This concise yet in-depth guide takes you inside scope and closures, two core concepts you need to know to become a more efficient and effective JavaScript programmer. You'll learn how and why they work, and how an understanding of closures can be a powerful part of yo ...more
Paperback, 98 pages
Published April 1st 2014 by O'Reilly Media (first published January 1st 2014)
More Details... Edit Details

Friend Reviews

To see what your friends thought of this book, please sign up.

Reader Q&A

To ask other readers questions about You Don't Know JS, please sign up.

Be the first to ask a question about You Don't Know JS

Community Reviews

Showing 1-30
Average rating 4.55  · 
Rating details
 ·  1,623 ratings  ·  123 reviews

More filters
Sort order
Start your review of You Don't Know JS: Scope and Closures (You Don't Know JS, #2)
Jun 24, 2015 rated it it was amazing
Does a programming book get better than this? I don't think so.
Ilya Ivanov
Sep 21, 2015 rated it it was amazing
Marvelous book. Kyle deserves every cent received at Kickstarter.

The book is so concise, that it seems like every word is brushed until it shines, revealing the underlying truth about JavaScript and it's key differences from other languages.

Topics covered: scope, different types of scope, modules, IFFE, hoisting, closures, polyfilling. Code samples are short, intention revealing and very informative.

I've been through two books in this series and very thrilled to dive deeper into next books.

Dave Peticolas
Nov 22, 2015 rated it really liked it
What a great little book. This might be the first Javascript book I've managed to finish without having my eyes glaze over from the tedium. Modern technical books tend to lean far too much on how-to examples and not enough time on deeper explanations. This book focuses on one particular aspect of the language, scope rules and closures, and explains it in depth. The author understands how important well-crafted analogies and mental models are for achieving genuine understanding.
Temo Tchanukvadze
Oct 14, 2018 rated it it was amazing
Shelves: js
Recommended! It doesn't matter how good/bad JS developer you are. You need to fill your gaps and YDKJS is the best choice.
Irakli Iremashvili
Mar 08, 2019 rated it it was amazing
For most newcomers to Javascript (whether they know any other programming language or not), it's scope and closure behaviour may seem very strange. This book helps you understand this topic and become a better developer
Sep 11, 2018 rated it liked it
You can find a full review of this book at Tiffany R. White Blog. ...more
Oct 27, 2015 rated it it was amazing
Shelves: non-fiction
Excellent book, which describes the subject to its full extent.
Nov 12, 2018 rated it it was amazing
Shelves: tech, programming
Short, to the point, clearly explained, and written with a bit of humor. A delight to read.
Heba Atallah
Oct 13, 2017 rated it it was amazing
Shelves: javascript
That's what I'm calling the perfect book
Apr 04, 2018 rated it really liked it  ·  review of another edition
Not a bad deep dive into scope & closures. I picked up a good amount along the way. I'd definitely supplement this with YouTube videos to follow up. ...more
Jul 25, 2015 rated it it was amazing
Shelves: programming
Awesome book. Helped me gain a better understanding of Scope and Closures and clear up some misconceptions! Before reading this book i actually thought JavaScript is an interpreted language but learned it is in fact a compiled language but its different from other compiled languages because compilation does not happen well in advance rather just milliseconds before execution. I also liked his definition of a closure, 'Closure is when a function is able to remember and access its lexical scope ev ...more
Jun 03, 2015 rated it it was amazing
I needed something to explain scopes and closures to a Junior Dev I've started working with and mentoring recently. The usual examples and code samples weren't clicking, and I began to realize that, even for me, those old stand-by's weren't what actually got me to grock closure. I had to use the module pattern extensively before I really understood the concept at an intuitive level.

This book fills in what I needed experience to understand. It is concise, it is accurate, it is clear. You can't as
Dec 03, 2017 rated it liked it
Perhaps not worthy of a stand-alone title. And don't really agree with all of the advices regarding let.

The author's advice is also contradictory in the spirit of the series which is to understand deeply and then use it correctly.

On the other hand, for let the recommended use is only for block scope and even then make it explicit with braces. Ahem, that's why you use the new keyword 'let'.

If your code breaks after replacing var with let, you weren't writing very clean code in the first place.
Joshua Isaac
Mar 19, 2015 rated it it was amazing
Shelves: programming
This book was a nice refresher of things I already knew, as well as a tidy introduction to some new syntax in EC6. I appreciated his coverage of IIFEs because that's syntax I'm always very confused about. This book was explicit in its scope (hah!) - it really didn't touch on much else besides scopes and closures - but it also didn't shy away from telling you about powerful language functions just because they are not nice to think about.
Robson Castilho
Dec 15, 2016 rated it really liked it
Shelves: software
Concepts such as lexical scopes, function and block scopes, closures, module pattern, IIFE and hoisting are all well explained with simple code examples. At the start, a very good intro about Javascript compilation process, its compiler and engine.
Additionally, some new ES6 features are presented in conjuction with pollyfill solutions for block scopes.
A very good book for those who wants to understand how JS works!
Jeff Richardson
Jun 09, 2014 rated it it was amazing
While I already considered myself somewhat of an expert when it came to scope and closure, I've read and heard Crockford talk about them a lot over the years, and Zakas books have a wealth of information on scope and closures as well I feel this book provided a new light on them. I'm a better Client Side Engineer for having read this book.
Hưng Đặng
Sep 09, 2018 rated it really liked it
It is surprising that this good book is not too much beyond my comprehension of the language and my meager experience in the field is also a great help. Few things that I might need to go over again because I am still confused with them:

1. JS is compiled, it is not just interpreted

2. Tokenizing and lexing.

3. JS conpilation doens't work in a build step ahead of time like other language. So I guess it works in run time!

4. LHS cares about target of the assignment while RHS wants to know about the s
Md. Jamal Uddin
Sep 29, 2018 rated it really liked it
Shelves: computer-science
Engine: Hey Scope, I have an RHS reference for foo. Ever heard of it?

Scope: Why yes, I have. Compiler declared it just a second ago. He's a function. Here you go.

Engine: Great, thanks! OK, I'm executing foo.

Engine: Hey, Scope, I've got an LHS reference for a, ever heard of it?

Scope: Why yes, I have. Compiler declared it as a formal parameter to foo just recently. Here you go.

Engine: Helpful as always, Scope. Thanks again. Now, time to assign 2 to a.

Engine: Hey, Scope, sorry to bother you again.
Jul 16, 2017 rated it it was amazing  ·  review of another edition
Excellent coverage over these topics. One part I appreciated so much was that these topics are rarely covered well in any learning book, but are covered very well here, with reference to other ways for a more complete understanding. Kyle tells us about dynamic scoping and highlights the potential pitfalls of an area that is a mixture ("this" which in one context operates with lexical scope and in another case operates with dynamic scope). For me, the real attraction was a good understanding of c ...more
Sep 06, 2017 rated it it was amazing
Did you know JavaScript is actually a compiled language? You probably did not. This and many other mind-blowing discoveries is what you will find after reading this book.

I learned what I know about JavaScript the usual way: try something; see it failing; try something else; see it working, but not really understanding why; move on with life.

This book enlightens you with the inner workings of JavaScript, specifically with something you use at every single JavaScript snippet you write, scope. It
Yanjia Li
Aug 06, 2018 rated it it was amazing
Another must read for Javascript developers who want to understand the mechanism behind the scene. Unlike Types & Grammar which somewhat looks tricky, the knowledge in this book could really help in work. This is one of the few books that explains what is closure and why it's called closure. To simply put, a closure close a scope. But maybe most of JS developers don't even understand lexical scope much, which prevent them from understanding closures more thoroughly. And the author caught that pr ...more
May 13, 2018 rated it really liked it  ·  review of another edition
I've puzzled through enough JavaScript to develop an intuitive sense of scope and closure. But the temptation is to never give it much thought in the name of churning out code that works. The reality is that "What is Closure?" is an incredibly common interview question for almost any tech screen and it pays to develop a vocabulary for discussing it.

The additional study of how to leverage an understanding of closure in one's code is invaluable. And clearly about to lead into a long discussion of
Dawn Saquin
Jul 26, 2018 rated it really liked it
Great book that helped me understand a little more about function and block scoping, and how to point out closures. I also got a clearer picture on when to use the variable declarations let and const.
I still have a few uncertainties about using 'this' and arrow functions together, since Kyle says to avoid it and stick to one. I guess I'll know more about it in the next book in the series. : )

Overall, this book helps me think more like a JS programmer and to know that functions are powerful in
Kevin Sweet
Aug 25, 2019 rated it it was ok
This installment in YDKJS focused too much on the parts of JS that you're probably not using anymore. Yes, var has a lot of idiosyncrasies. That's why we use const now, but the book spent two sentences offhandedly mentioning const.

JavaScript has a lot of baggage from its early days, but I would argue that learning the intricacies of how people used to write JavaScript isn't very useful today. Install ESLint, enable some recommended packages, and forget that it's possible to use those old feature
Anh Trinh
Mar 28, 2020 rated it really liked it
This is a great book, give me a lot of new knowledge. The concept of the scope of JavaScript is quite different from another programming language. Sometimes this book is quite wordy but I think that's because of the purpose to explain for very new programmers. And I think more comments on code example as Head First Series will make this book perfect. For developers who learned or make familiar with another programming language before, I think you should remove it from your mind temporarily to un ...more
Cathy Ha
Jun 09, 2020 rated it it was amazing
Deep and concise explanations of scopes and closures in Javascript, as well as a (useful and necessary) primer on how programming languages work in general. The book doesn't just teach you about good and bad coding practices, but helps you to develop a natural understanding of how things should be done by explaining the underpinnings of the Javascript language.

If you never quite understood hoisting or the difference between const, let and var - read this! I've never encountered a clearer explana
Jeremiah John
Sep 25, 2018 rated it it was amazing
I have heard it said that a JS developer's knowledge of scope practically determines their experience level.

This is the perfect book on scope; it is unsparing in its detail and thorough in edge cases.

If you've ever been in a code base touched by those who never heard the name "Crockford" then this is your book.
Julien Bérubé
Mar 06, 2019 rated it it was amazing
If you want a deep understanding of the underlying mechanism that makes javascript a powerful language - of if you just want to be able to debug those nasty closure bugs - this is THE book you need.
Cheap, and only 73 small pages full of diagram, so there is no excuses. This book have the highest value per page read.
If you're new to JavaScript, read "JavaScript: The Good Parts" first.
Jon Jones
Oct 21, 2019 rated it it was amazing
Scopes and closures we're one topic that always confused me around JS, even though I have read lots of blogs and online tutorials. this book goes into really good in-depth explanations and I finally understand and get how this complex subject works.

An essential read for all Javascript developers.
Bob Kozik
Dec 12, 2019 rated it really liked it
For what the book sets out to do it's very good, but I cannot stop wondering why and when the majority of the information presented will be useful. It's cool and interesting although I don't see it being practical in your typical web development workflow. Perhaps there are applications outside of web development? I'm not sure.
« previous 1 3 4 next »
There are no discussion topics on this book yet. Be the first to start one »

Readers also enjoyed

  • Eloquent JavaScript: A Modern Introduction to Programming
  • JavaScript: The Good Parts
  • Clean Code: A Handbook of Agile Software Craftsmanship
  • The Principles of Object-Oriented JavaScript
  • Grokking Algorithms An Illustrated Guide For Programmers and Other Curious People
  • HTML and CSS: Design and Build Websites
  • JavaScript: The Definitive Guide
  • Code Complete
  • The Pragmatic Programmer: From Journeyman to Master
  • Refactoring: Improving the Design of Existing Code
  • The Mythical Man-Month: Essays on Software Engineering
  • Head First Design Patterns
  • Design Patterns: Elements of Reusable Object-Oriented Software
  • Secrets of the JavaScript Ninja
  • 97 Things Every Programmer Should Know: Collective Wisdom from the Experts
  • Domain-Driven Design: Tackling Complexity in the Heart of Software
  • Clean Architecture
  • JavaScript and jQuery: Interactive Front-End Web Development
See similar books…

Goodreads is hiring!

If you like books and love to build cool products, we may be looking for you.
Learn more »
Kyle Simpson is an Open Web Evangelist from Austin, TX, who's passionate about all things JavaScript. He's an author, workshop trainer, tech speaker, and OSS contributor/leader.

Other books in the series

You Don't Know JS (6 books)
  • You Don't Know JS: Up & Going
  • You Don't Know JS: this & Object Prototypes
  • You Don't Know JS: Types & Grammar
  • You Don't Know JS: Async & Performance
  • You Don't Know JS: ES6 & Beyond

News & Interviews

From independent presses, to tales in translation, to critical darlings and new debut novels, these books (all published in the U.S. this year)...
31 likes · 3 comments
“Closure is when a function is able to remember and access its lexical scope even when that function is executing outside its lexical scope.” 5 likes
More quotes…