Secrets of the JavaScript Ninja

Author: John Resig, Bibeault, Josip Maras
This Month Stack Overflow 2

About This Book

More than ever, the web is a universal platform for all types of applications, and JavaScript is the language of the web. If you're serious about web development, it's not enough to be a decent JavaScript coder. You need to be ninja-stealthy, efficient, and ready for anything. This book shows you how.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the Technology

JavaScript is rapidly becoming a universal language for every type of application, whether on the web, on the desktop, in the cloud, or on mobile devices. When you become a JavaScript pro, you have a powerful skill set that's usable across all these domains.

About the Book

Secrets of the JavaScript Ninja, Second Edition uses practical examples to clearly illustrate each core concept and technique. This completely revised edition shows you how to master key JavaScript concepts such as functions, closures, objects, prototypes, and promises. It covers APIs such as the DOM, events, and timers. You'll discover best practice techniques such as testing, and cross-browser development, all taught from the perspective of skilled JavaScript practitioners.

What's Inside

  • Writing more effective code with functions, objects, and closures
  • Learning to avoid JavaScript application pitfalls
  • Using regular expressions to write succinct text-processing code
  • Managing asynchronous code with promises
  • Fully revised to cover concepts from ES6 and ES7


by anonymous   2018-03-18

It doesn't work that way. When you define a timer (setTimeout or setInterval) the JS engine doesn't guarantee that it will run in 1,000 ms because it depends on what it's processing in the queue.

Also, the timer doesn't add a task in the queue if it already exists. This means that if the timer expires and there's already an instance in the queue for that timer, then it's not added again.

I recommend you this book: It has a chapter about events and it explains exactly what you are asking.

by anonymous   2018-02-26
var array = [1,2,3]; 

It doesn't call push but it's a simpler way to initialize an array when you know the elements in advance.

If you want to add another element you can do it in multiple ways like:

1) array.push(22); // adds integer 22 to the array


2) array[4] = 22; // adds integer 22 to the array at index 4

You can even do this:

array[20] = 22; // this will resize the array and keep all the uninitialized elements returns undefined. So array[10] is undefined, for ex.

If you want to know all the details about arrays explained in a simple way I recommend you the book: Secrets of the JavaScript Ninja. It has an entire chapter about arrays.