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! 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
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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
€18.99 per month
Paperback Dec 2018 642 pages 1st Edition
eBook
€26.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Federico Kereki
Arrow right icon
€18.99 per month
Paperback Dec 2018 642 pages 1st Edition
eBook
€26.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€26.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. €18.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788992749
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. €18.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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 €5 each
Feature tick icon Exclusive print discounts
€264.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 €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 102.97
Building Enterprise JavaScript Applications
€36.99
Modern JavaScript Web Development Cookbook
€36.99
Advanced JavaScript
€28.99
Total 102.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.