JavaScript is an essential part of programming on the Salesforce platform. However, since it is dynamic and loosely typed, it is prone to programmer errors. Common mistakes can lead to pull-out-your-hair issues and bad coding practices not only affect the performance, but the security of your apps and data as well.
In this session, you’ll look at an inefficient code sample riddled with bad practices, memory leaks and bugs. You’ll learn how to identify and fix each of them. You’ll walk away with an understanding of how to write better JavaScript code and apply a few best practices that improve your code quality and maintainability.
Here is the agenda:
- Evolution of JavaScript and Shorthand Syntax
- Common Mistakes
- Type Coercion
- Null vs undefined
- Incorrect references to “this”
- Data references and leaks
- Insecure Code
- Inefficient DOM Access
- ESLint
Evolution of JavaScript
Introducing Shorthand Syntax
Declaring an object, where the variable and object property name are the same
String Concatenation
Anonymous Functions
Insecure Code
SOQL query exposed to the browser
- Use APEX for business logic like making callouts and database operations.
- Never trust the data coming from the browser/client.
- Remember that minification is not a security feature.
- Enforce proper scoping when using cookies.
ESLINT
- Linting is a process of analyzing code for potential errors.
- Enforces Secure Coding and Best Practices
- Integrates as a plugin to VS Code.
- Enforces Rules like
- Disallow Assignment to undeclared variables
- Require the use of === and !==
- Disallow the use of alert, confirm, and prompt.
- Disallow unused variables
Recording
Date : Saturday, APR 04, 2020 10:00 AM EST (7:30 PM IST ) Speaker : Aditya Naag Topalli |
Further Learning
- https://code.tutsplus.com/tutorials/24-javascript-best-practices-for-beginners–net-5399
- https://www.toptal.com/javascript/10-most-common-javascript-mistakes
- https://dmitripavlutin.com/unlearn-javascript-bad-coding-habits/
- https://medium.com/better-programming/never-write-another-for-loop-in-javascript-9db11afa6445
Bookmarks our “Session in 2020” page for all upcoming and old sessions of 2020. Let us know which topic you want learn next in ApexHours.
If you are new in Salesforce. Please check our free Salesforce Admin and Salesforce Developer training. Subscribe to the channel if you haven’t already
Thanks,
Salesforce Apex Hours
Awesome, 👌👍