JavaScript: Best Practices for Functions and Classes
1h 45mIntermediate2020-10-15
Authors

Sasha Vodnik
Principal Technical Course Developer at DocuSign
Course details
JavaScript uses C-based syntax, but the structures at its core, namely functions and classes, behave very differently than C behaves. Leveraging recommended techniques can help you develop JavaScript code that is more consistent and easier to maintain. In this course, explore best practices for architecting your programs. Consider ways that details can take paths that differ from other programming languages. Learn about creating well-built, organized, modular, and high-quality code by using a style guide, modern deployment tools, and strict mode. Discover how to carefully construct functions using more predictable expressions over declarations and by avoiding the modification of parameter values. Examine the dos—and don’ts—of “this” values and learn about which JavaScript features to avoid.
Skills covered
JavaScriptOracleProgramming LanguagesSoftware DevelopmentDeep Dive (X:Y)
Concepts
0. Introduction
- 01 - Creating well-structured modular JavaScript
- 02 - What you should know
- 03 - Setting up your environment
1. Why Best Practices
- 04 - Understanding style guides
- 05 - Using modern deployment tools
- 06 - Understanding ESLint
- 07 - Foundational practice - Always use strict mode
2. Creating Functions
- 08 - Use function expressions instead of declarations
- 09 - Don't use the new keyword to construct functions
- 10 - Leave parameter values untouched
- 11 - Use arrow syntax for anonymous functions
- 12 - Rely on implicit return only when obvious
- 13 - Challenge - Create functions
- 14 - Solution - Create functions
3. Creating Classes
- 15 - Use PascalCase for naming classes and constructors
- 16 - Use this only in classes or constructors
- 17 - Return this from methods
- 18 - Don't assign this to another variable
- 19 - Challenge - Create classes
- 20 - Solution - Create classes
4. Creating Modules
- 21 - Configure module settings in ESLint
- 22 - Default export constants when possible
- 23 - Use case to indicate a module's default export type
5. Destructuring
- 24 - Use object destructuring
- 25 - Use array destructuring
- 26 - Challenge - Destructure
- 27 - Solution - Destructure
6. JavaScript Features to Avoid
- 28 - Avoid eval
- 29 - Avoid and
- 30 - Avoid with
- 31 - Avoid unary increments and decrements
Conclusion
- 32 - Next steps
Related courses
- CompTIA PenTest+ (PT0-002) Cert Prep: 5 Tools and Code Analysis
- jQuery for Web Designers
- Building TypeScript Applications with JSDoc
- Data Structures in JavaScript: BSTs, Queues, and Stacks
- Learn JavaScript: Write Modern Code with JavaScript ESNext
- Computer Science Principles Lab: JavaScript
- Crossfilter for Data Science Essential Training
- React Best Practices by Pearson