Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Modern JavaScript Web Development Cookbook
Modern JavaScript Web Development Cookbook

Modern JavaScript Web Development Cookbook: Easy solutions to common and everyday JavaScript development problems

Arrow left icon
Profile Icon Federico Kereki
Arrow right icon
₱1399.99 ₱2000.99
eBook Dec 2018 642 pages 1st Edition
eBook
₱1399.99 ₱2000.99
Paperback
₱2500.99
Subscription
Free Trial
Arrow left icon
Profile Icon Federico Kereki
Arrow right icon
₱1399.99 ₱2000.99
eBook Dec 2018 642 pages 1st Edition
eBook
₱1399.99 ₱2000.99
Paperback
₱2500.99
Subscription
Free Trial
eBook
₱1399.99 ₱2000.99
Paperback
₱2500.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Modern JavaScript Web Development Cookbook

Using Modern JavaScript Features

The recipes we will be covering in this chapter are as follows:

  • Adding types
  • Working with strings
  • Enhancing your code
  • Defining functions
  • Programming functionally
  • Doing async calls compactly
  • Working with objects and classes
  • Organizing code in modules
  • Determining a feature's availability

Introduction

In the previous chapter, we set up our working environment with many tools that we will be using throughout this book. In this chapter, we will get ourselves prepared for the rest of this book, and we will be considering some interesting and powerful modern features of JavaScript that can you help be more effective and write better code.

We will be considering several new language features that will come handy—but definitely not everything! JS has really grown into a big language, and there are some features that you're not likely to ever need. From the very start, we will also work more seriously with Flow, aiming to forego the usage of untyped JS, for a safer way of developing code.

It may be important to highlight that JS has evolved through the years, and that there isn't a single standard version. The most recent one is (formally) called ECMAScript...

Adding types

In the previous chapter, we installed Flow so that we could add data types check to JS, but we didn't really get into its syntax or rules. Let's get into that now, before getting into JS-specific features.

Getting started

Flow will not check every file unless you expressly require it to. For a file to be checked, you must add a simple comment to the very top, as shown in the following code snippet. Flow will ignore any files that lack this comment, so even if you were adding the tool to an already existing project, you could do it gradually, adding files one at a time:

/* @flow */

Starting with Flow's controls, you just have to specify what data type you expect any variable to be, and Flow will...

Working with strings

Strings have been a feature of JS since the very first version, but nowadays there are some more features available.

How to do it...

In the following sections, we'll see many functions that we'll be using through the rest of this book, such as interpolation (to build up strings out of several parts) or tagged strings (which we'll use to style components in the Creating StyledComponents for inline styling section of Chapter 7, Enhancing Your Application), to show just two examples.

Interpolating in template strings

Everybody has, at one...

Enhancing your code

Now, let's go over several useful new functions of JS, which have to do with basic needs and features. This won't be exhaustive, since JS is quite big, after all! However, we will touch on the most interesting features that you will be likely to use.

How to do it...

The features in this section aren't linked by a common thread, apart from the fact that they will help you to write shorter, more concise code and help you to avoid possible common errors.

Working in strict mode

Let's start with a change that you probably won't need...

Defining functions

JS isn't a functional programming language by definition, but it includes practically everything that a full-fledged functional language would provide. In our case, we won't be delving too deeply into this programming paradigm, but let's see some important features that will simplify your work.

How to do it...

JS has always included functions, which can be defined in many ways, but now there is yet one more function definition style that will provide several advantages; read on.

Writing arrow functions

After reading the preceding paragraph...

Programming functionally

Functional programming is often more declarative than imperative, with higher level functions that can do complete processing in a simpler, straightforward way. Here, let's look at several functional programming techniques that you should really adopt for your own code.

How to do it...

Functional programming has always been present in JS, but recent versions of the language have added well-known features of other languages that you can use to shorten your code, also making it simpler to understand.

Reducing arrays to values

A simple question...

Doing async calls compactly

When Ajax started appearing, it was commonly used with callbacks, which themselves could have callbacks of their own, with more callbacks within, which eventually led to coining the term callback hell. As a way out of that impractical programming style, two other styles of working with services and asynchronous calls appeared: promises and async/await—though in truth, the latter also use promises!

Getting started

Let's see both styles by using a simple example. This book was written in three different cities: Pune, India; London, England; and Montevideo, Uruguay, so let's do some work related to those cities. We will write code that will get weather information for those cities...

Working with objects and classes

If you want to start a lively discussion, ask a group of web developers: is JavaScript an object oriented language, or merely an object based one?, and retreat quickly! This discussion, while possibly arcane, has gone on year after year, and will probably continue for a while. A usual argument for the object-based opinion has to do with the fact that JS didn't include classes and inheritance and was prototype oriented. This argument has been voided now because the latest versions of JS provide two new keywords, class and extends, which behave in pretty much the same way as their counterparts in other official OO languages. However, keep in mind that the new classes are just syntactical sugar over the existing prototype-based inheritance; no new paradigm or model was truly introduced.

JS could do inheritance, but it was harder. To see how this...

Organizing code in modules

As today's JS applications become more and more complex, working with namespaces and dependencies becomes ever more difficult to handle. A key solution to this problem was the concept of modules, which allows you to partition your solution in independent parts, taking advantage of encapsulation to avoid conflict between different modules. In this section, we'll look at how to work in this fashion. However, we'll start with a previous JS pattern, which may become useful in its own way.

Node, which we'll be working with starting with the next chapter, also does modules but in a different fashion, so we'll postpone the discussion of its modules for now.

How to do it...

Organizing...

Determining a feature's availability

To round off this chapter, let me introduce two web tools that can help you be aware about what features you can safely use and which will make a transpiler (such as Babel, which we mentioned at the start of this chapter) necessary.

How to do it...

Your first resource will be https://kangax.github.io/compat-table/, which provides very thorough and complete tables showing, feature by feature, what is supported on JS engines everywhere. Depending on your specific needs, you might be able to totally dispense with transpiling, but it's certain you should be careful before taking such a measure!

The following screenshot shows Kangax at work:

The Kangax website lets you determine...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Over 90 practical recipes to help you write clean and maintainable JavaScript codes with the latest ES8
  • Leverage the power of leading web frameworks like Node and React to build modern web apps
  • Features comprehensive coverage of tools and techniques needed to create multi-platform apps with JavaScript

Description

JavaScript has evolved into a language that you can use on any platform. Modern JavaScript Web Development Cookbook is a perfect blend of solutions for traditional JavaScript development and modern areas that developers have lately been exploring with JavaScript. This comprehensive guide teaches you how to work with JavaScript on servers, browsers, mobile phones and desktops. You will start by exploring the new features of ES8. You will then move on to learning the use of ES8 on servers (with Node.js), with the objective of producing services and microservices and dealing with authentication and CORS. Once you get accustomed to ES8, you will learn to apply it to browsers using frameworks, such as React and Redux, which interact through Ajax with services. You will then understand the use of a modern framework to develop the UI. In addition to this, development for mobile devices with React Native will walk you through the benefits of creating native apps, both for Android and iOS. Finally, you’ll be able to apply your new-found knowledge of server-side and client-side tools to develop applications with Electron.

Who is this book for?

This book is for developers who want to explore the latest JavaScript features, frameworks, and tools for building complete mobile, desktop and web apps, including server and client-side code. You are expected to have working knowledge of JavaScript to get the most out of this book.

What you will learn

  • Use the latest features of ES8 and learn new ways to code with JavaScript
  • Develop server-side services and microservices with Node.js
  • Learn to do unit testing and to debug your code
  • Build client-side web applications using React and Redux
  • Create native mobile applications for Android and iOS with React Native
  • Write desktop applications with Electron

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2018
Length: 642 pages
Edition : 1st
Language : English
ISBN-13 : 9781788992350
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Dec 26, 2018
Length: 642 pages
Edition : 1st
Language : English
ISBN-13 : 9781788992350
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 6,991.97
Advanced JavaScript
₱1989.99
Modern JavaScript Web Development Cookbook
₱2500.99
Building Enterprise JavaScript Applications
₱2500.99
Total 6,991.97 Stars icon

Table of Contents

14 Chapters
Working with JavaScript Development Tools Chevron down icon Chevron up icon
Using Modern JavaScript Features Chevron down icon Chevron up icon
Developing with Node Chevron down icon Chevron up icon
Implementing RESTful Services with Node Chevron down icon Chevron up icon
Testing and Debugging Your Server Chevron down icon Chevron up icon
Developing with React Chevron down icon Chevron up icon
Enhancing Your Application Chevron down icon Chevron up icon
Expanding Your Application Chevron down icon Chevron up icon
Debugging Your Application Chevron down icon Chevron up icon
Testing Your Application Chevron down icon Chevron up icon
Creating Mobile Apps with React Native Chevron down icon Chevron up icon
Testing and Debugging Your Mobile App Chevron down icon Chevron up icon
Creating a Desktop Application with Electron Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.