You are previewing JavaScript Unlocked.
O'Reilly logo
JavaScript Unlocked

Book Description

Improve your code maintainability, performance, and security through practical expert insights and unlock the full potential of JavaScript

About This Book

  • Improve your JavaScript code for better maintainability and performance

  • Discover how to implement scalable application architecture with JavaScript

  • Learn to use JavaScript behind the browser, including its command-line tools, desktop apps, and native mobile apps

  • Who This Book Is For

    JavaScript Unlocked is for those JS developers who want to see just how far they can push their favourite language through practical insight and techniques.

    What You Will Learn

  • Make your code readable and expressive by using simple syntax of JavaScript

  • Grasp existing JavaScript collections such as arrays and array-like objects

  • Develop abstract data types in most effective way to extend JavaScript into a more flexible and powerful programming language

  • Examine the pros and cons of JavaScript by implementing real-time code examples

  • Flourish real-time mini-projects by using JavaScript on server side to develop desktop as well as mobile applications

  • Work on parallel tasks with asynchronous JavaScript

  • Improve code maintainability and readability and boost apps performance through JavaScript

  • In Detail

    JavaScript stands bestride the world like a colossus. Having conquered web development, it now advances into new areas such as server scripting, desktop and mobile development, game scripting, and more. One of the most essential languages for any modern developer, the fully-engaged JavaScript programmer need to know the tricks, non-documented features, quirks, and best practices of this powerful, adaptive language.

    This all-practical guide is stuffed with code recipes and keys to help you unlock the full potential of JavaScript. Start by diving right into the core of JavaScript, with power user techniques for getting better maintainability and performance from the basic building blocks of your code. Get to grips with modular programming to bring real power to the browser, master client-side JavaScript scripting without jQuery or other frameworks, and discover the full potential of asynchronous coding. Do great things with HTML5 APIs, including building your first web component, tackle the essential requirements of writing large-scale applications, and optimize JavaScript’s performance behind the browser. Wrap up with in-depth advice and best practice for debugging and keeping your JavaScript maintainable for scaling, long-term projects. With every task demonstrated in both classic ES5 JavaScript and next generation ES6-7 versions of the language, Whether read cover-to-cover or dipped into for specific keys and recipes, JavaScript Unlocked is your essential guide for pushing JavaScript to its limits.

    Style and approach

    This practice-oriented cookbook is packed full of code examples put in the form: problem, classical solution, and methods to optimize webpage in both JavaScript ES5 and ES6 language editions. But this thorough guide is best-suited to those who like to “learn by doing” as the topics are covered using real-life examples and tutorials.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. JavaScript Unlocked
      1. Table of Contents
      2. JavaScript Unlocked
      3. Credits
      4. About the Author
      5. About the Reviewer
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Diving into the JavaScript Core
        1. Make your code readable and expressive
          1. Function argument default value
          2. Conditional invocation
          3. Arrow functions
          4. Method definitions
          5. The rest operator
          6. The spread operator
        2. Mastering multiline strings in JavaScript
          1. Concatenation versus array join
          2. Template literal
          3. Multi-line strings via transpilers
        3. Manipulating arrays in the ES5 way
          1. Array methods in ES5
          2. Array methods in ES6
        4. Traversing an object in an elegant, reliable, safe, and fast way
          1. Iterating the key-value object safely and fast
          2. Enumerating an array-like object
          3. The collections of ES6
        5. The most effective way of declaring objects
          1. Classical approach
          2. Approach with the private state
          3. Inheritance with the prototype chain
          4. Inheriting from prototype with Object.create
            1. Inheriting from prototype with Object.assign
          5. Approach with ExtendClass
          6. Classes in ES6
        6. How to – magic methods in JavaScript
          1. Accessors in ES6 classes
          2. Controlling access to arbitrary properties
        7. Summary
      9. 2. Modular Programming with JavaScript
        1. How to get out of a mess using modular JavaScript
          1. Modules
            1. Cleaner global scope
            2. Packaging code into files
            3. Reuse
          2. Module patterns
          3. Augmentation
          4. Module standards
        2. How to use asynchronous modules in the browser
          1. Pros and cons
        3. How to – use synchronous modules on the server
          1. Pros and cons
          2. UMD
        4. JavaScript's built-in module system
          1. Named exports
          2. Default export
          3. The module loader API
          4. Conclusion
        5. Transpiling CommonJS for in-browser use
          1. Bundling ES6 modules for synchronous loading
        6. Summary
      10. 3. DOM Scripting and AJAX
        1. High-speed DOM operations
          1. Traversing the DOM
          2. Changing the DOM
          3. Styling the DOM
          4. Making use of attributes and properties
          5. Handling DOM events
        2. Communicating with the server
          1. XHR
          2. Fetch API
        3. Summary
      11. 4. HTML5 APIs
        1. Storing data in web-browser
          1. Web Storage API
          2. IndexedDB
          3. FileSystem API
        2. Boosting performance with JavaScript workers
        3. Creating the first web component
        4. Learning to use server-to-browser communication channels
          1. Server-Sent Events
          2. Web Sockets
        5. Summary
      12. 5. Asynchronous JavaScript
        1. Nonblocking JavaScript
        2. Error-first Callback
        3. Continuation-passing style
        4. Handling asynchronous functions in the ES7 way
        5. Parallel tasks and task series with the Async.js library
        6. Event handling optimization
          1. Debouncing
          2. Throttling
          3. Writing callbacks that don't impact latency-critical events
        7. Summary
      13. 6. A Large-Scale JavaScript Application Architecture
        1. Design patterns in JavaScript
        2. Understanding concern separation in JavaScript
          1. MVVM
        3. Using JavaScript MV* frameworks
          1. Backbone
          2. Angular
          3. React
        4. Summary
      14. 7. JavaScript Beyond the Browser
        1. Levelling up the coding of a command-line program in JavaScript
        2. Building a web server with JavaScript
        3. Writing a desktop HTML5 application
          1. Setting up the project
          2. Adding the HTML5 application
          3. Debugging
          4. Packaging
        4. Using PhoneGap to make a mobile native app
          1. Setting up the project
          2. Building the project
          3. Adding plugins
          4. Debugging
        5. Summary
      15. 8. Debugging and Profiling
        1. Hunting bugs
        2. Getting the best from a console API
        3. Tuning performance
        4. Summary
      16. Index