JavaScript: Best Practice
By James Kolce, Moritz Kroger, Ivan Curic and
3.5/5
()
About this ebook
There's no doubt that the JavaScript ecosystem changes fast. Not only are new tools and frameworks introduced and developed at a rapid rate, the language itself has undergone big changes with the introduction of ES2015 (aka ES6). Understandably, many articles have been written complaining about how difficult it is to learn modern JavaScript development these days. We're aiming to minimize that confusion with this set of books on modern JavaScript.
This book presents modern JavaScript best practice, utilizing the features now available in the language that enable you to write more powerful code that is clean, performant, maintainable, and resusable. It contains:
- The Anatomy of a Modern JavaScript Application by James Kolce
- Clean Code with ES6 Default Parameters & Property Shorthands by Moritz Kruger
- JavaScript Performance Optimization Tips: An Overview by Ivan CuriC
- JavaScript Design Patterns: The Singleton by Samier Saeed
- JavaScript Object Creation: Patterns and Best Practices by Jeff Mott
- Best Practices for Using Modern JavaScript Syntax by M. David Green
- Flow Control in Modern JS: Callbacks to Promises to Async/Await by Craig Buckler
- JavaScript's New Private Class Fields, and How to Use Them by Craig Buckler
This book is for all front-end developers who wish to improve their JavaScript skills. You'll need to be familiar with HTML and CSS and have a reasonable level of understanding of JavaScript in order to follow the discussion.
James Kolce
James Kolce is a self-taught 21-year-old designer and web developer based in Mexico. Lead developer of Concise CSS, a minimalist and extensible framework to build websites quickly with good design. He writes a blog called The Brain of James Kolce, were he puts some of the knowledge he has acquired over the years.
Related to JavaScript
Related ebooks
JavaScript Projects for Kids: Gear up for a roller-coaster ride into the world of JavaScript and programming with this easy-to-follow, fun, and entertaining project-based guide Rating: 0 out of 5 stars0 ratingsJavaScript Enlightenment Rating: 4 out of 5 stars4/5Professional JavaScript for Web Developers Rating: 5 out of 5 stars5/5Mastering JavaScript Object-Oriented Programming Rating: 0 out of 5 stars0 ratingsTypeScript Essentials Rating: 4 out of 5 stars4/5Practical Advanced TypeScript Rating: 0 out of 5 stars0 ratingsLearn Vue.js 2.0 in 7 Days: Journey through Vue.js Rating: 0 out of 5 stars0 ratingsMastering JavaScript Design Patterns Rating: 4 out of 5 stars4/5Front-end Development with ASP.NET Core, Angular, and Bootstrap Rating: 0 out of 5 stars0 ratingsClean Code in JavaScript: Develop reliable, maintainable, and robust JavaScript Rating: 4 out of 5 stars4/5Exploring Web Components: Build Reusable UI Web Components with Standard Technologies (English Edition) Rating: 0 out of 5 stars0 ratingsLearning JavaScript Data Structures and Algorithms Rating: 5 out of 5 stars5/5React Design Patterns and Best Practices Rating: 0 out of 5 stars0 ratingsNode.js Design Patterns - Second Edition Rating: 4 out of 5 stars4/5Object-Oriented JavaScript: Create scalable, reusable high-quality JavaScript applications, and libraries Rating: 3 out of 5 stars3/5ReactJS by Example - Building Modern Web Applications with React Rating: 4 out of 5 stars4/5Dart Cookbook Rating: 0 out of 5 stars0 ratingsReact.js Design Patterns: Learn how to build scalable React apps with ease (English Edition) Rating: 0 out of 5 stars0 ratingsUnleashing the Power of TypeScript Rating: 2 out of 5 stars2/5Object-Oriented JavaScript Rating: 4 out of 5 stars4/5Mastering JavaScript: The Complete Guide to JavaScript Mastery Rating: 5 out of 5 stars5/5Node.js Web Development - Third Edition Rating: 2 out of 5 stars2/5iOS 15 Application Development for Beginners: Learn Swift Programming and Build iPhone Apps with SwiftUI and Xcode 13 Rating: 0 out of 5 stars0 ratingsWb Development full course : from zero to web hero Rating: 0 out of 5 stars0 ratingsCoding with JavaScript For Dummies Rating: 5 out of 5 stars5/5Mastering JavaScript Design Patterns - Second Edition Rating: 5 out of 5 stars5/5TypeScript Design Patterns Rating: 0 out of 5 stars0 ratings
Programming For You
Creating ELearning Games with Unity Rating: 0 out of 5 stars0 ratingsLearn SAP BI in 24 Hours Rating: 3 out of 5 stars3/5PowerShell 7 for IT Professionals Rating: 1 out of 5 stars1/5Programming in Python: Learn the Powerful Object-Oriented Programming Rating: 0 out of 5 stars0 ratingsProxmox Administration Essentials: Definitive Reference for Developers and Engineers Rating: 0 out of 5 stars0 ratingsThe Book of Powershell Rating: 0 out of 5 stars0 ratingsLearning LEGO MINDSTORMS EV3 Rating: 5 out of 5 stars5/5PHP & MySQL Practice It Learn It Rating: 4 out of 5 stars4/5PHP, MySQL, & JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5iOS 26 App Development Essentials - SwiftUI Edition: Developing iOS 26 Apps using SwiftUI, Swift and Xcode 26 Rating: 0 out of 5 stars0 ratingsSAP Service Management - Advanced Configuration Guide 2 Rating: 0 out of 5 stars0 ratingsJavaScript Made Easy: A Beginner's Practical Guide to Coding Interactive Web Pages Rating: 0 out of 5 stars0 ratingsOntotext GraphDB in Practice: The Complete Guide for Developers and Engineers Rating: 0 out of 5 stars0 ratingsSwipe This!: The Guide to Great Touchscreen Game Design Rating: 4 out of 5 stars4/5Unity Multiplayer Games Rating: 5 out of 5 stars5/5Web Designer's Idea Book, Volume 4: Inspiration from the Best Web Design Trends, Themes and Styles Rating: 4 out of 5 stars4/5Learn to Code with Scratch: Let Your Kids' Creative Ideas Come to Life by Coding Them into Programs Rating: 0 out of 5 stars0 ratingsJob Ready Python Rating: 0 out of 5 stars0 ratingsC# for Beginners: Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsPython For Kids For Dummies Rating: 0 out of 5 stars0 ratingsGood Luck Have Fun: The Rise of eSports Rating: 3 out of 5 stars3/5Hacking Android Rating: 5 out of 5 stars5/5OCP Oracle Certified Professional Java SE 11 Programmer II Study Guide: Exam 1Z0-816 and Exam 1Z0-817 Rating: 5 out of 5 stars5/5
Reviews for JavaScript
2 ratings0 reviews
Book preview
JavaScript - James Kolce
Chapter 1: The Anatomy of a Modern JavaScript Application
by James Kolce
There’s no doubt that the JavaScript ecosystem changes fast. Not only are new tools and frameworks introduced and developed at a rapid rate, the language itself has undergone big changes with the introduction of ES2015 (aka ES6). Understandably, many articles have been written complaining about how difficult it is to learn modern JavaScript development these days.
In this article, I’ll introduce you to modern JavaScript. We’ll take a look at recent developments in the language and get an overview of the tools and techniques currently used to write front-end web applications. If you’re just starting out with learning the language, or you’ve not touched it for a few years and are wondering what happened to the JavaScript you used to know, this article is for you.
A Note About Node.js
Node.js is a runtime that allows server-side programs to be written in JavaScript. It’s possible to have full-stack JavaScript applications, where both the front and back end of the app is written in the same language. Although this article is focused on client-side development, Node.js still plays an important role.
The arrival of Node.js had a significant impact on the JavaScript ecosystem, introducing the npm package manager and popularizing the CommonJS module format. Developers started to build more innovative tools and develop new approaches to blur the line between the browser, the server, and native applications.
JavaScript ES2015+
In 2015, the sixth version of ECMAScript — the specification that defines the JavaScript language — was released under the name of ES2015 (still often referred to as ES6). This new version included substantial additions to the language, making it easier and more feasible to build ambitious web applications. But improvements don’t stop with ES2015; each year, a new version is released.
Declaring variables
JavaScript now has two additional ways to declare variables: let and const.
let is the successor to var. Although var is still available, let limits the scope of variables to the block (rather than the function) they’re declared within, which reduces the room for error:
// ES5
for (var i = 1; i < 5; i++) {
console.log(i);
}
// <-- logs the numbers 1 to 4
console.log(i);
// <-- 5 (variable i still exists outside the loop)
// ES2015
for (let j = 1; j < 5; j++) {
console.log(j);
}
console.log(j);
// <-- 'Uncaught ReferenceError: j is not defined'
Using const allows you to define variables that cannot be rebound to new values. For primitive values such as strings and numbers, this results in something similar to a constant, as you cannot change the value once it has been declared:
const name = 'Bill';
name = 'Steve';
// <-- 'Uncaught TypeError: Assignment to constant variable.'
// Gotcha
const person = { name: 'Bill' };
person.name = 'Steve';
// person.name is now Steve.
// As we're not changing the object that person is bound to, JavaScript doesn't complain.
Arrow functions
Arrow functions provide a cleaner syntax for declaring anonymous functions (lambdas), dropping the function keyword and the return keyword when the body function only has one expression. This can allow you to write functional style code in a nicer way:
// ES5
var add = function(a, b) {
return a + b;
}
// ES2015
const add = (a, b) => a + b;
The other important feature of arrow functions is that they inherit the value of this from the context in which they are defined:
function Person(){
this.age = 0;
// ES5
setInterval(function() {
this.age++; // |this| refers to the global object
}, 1000);
// ES2015
setInterval(() => {
this.age++; // |this| properly refers to the person object
}, 1000);
}
var p = new Person();
Improved Class syntax
If you’re a fan of object-oriented programming, you might like the addition of classes to the language on top of the existent mechanism based on prototypes. While it’s mostly just syntactic sugar, it provides a cleaner syntax for developers trying to emulate classical object-orientation with prototypes.
class Person {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hello, my name is ${this.name}`);
}
}
Promises / Async functions
The asynchronous nature of JavaScript has long represented a challenge; any non-trivial application ran the risk of falling into a callback hell when dealing with things like Ajax requests.
Fortunately, ES2015 added native support for promises. Promises represent values that don’t exist at the moment of the computation but that may be available later, making the management of asynchronous function calls more manageable without getting into deeply nested callbacks.
ES2017 introduced async functions (sometimes referred to as async/await) that make improvements in this area, allowing you to treat asynchronous code as if it were synchronous:
async function
