What’s wrong with my JavaScript Code

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:

  1. Evolution of JavaScript and Shorthand Syntax
  2. Common Mistakes
    1. Type Coercion
    2. Null vs undefined
    3. Incorrect references to “this”
    4. Data references and leaks
    5. Insecure Code
    6. Inefficient DOM Access
  3. ESLint

Evolution of JavaScript

Introducing Shorthand Syntax

Declaring an object, where the variable and object property name are the same

JavaScript Shorthand Syntax

String Concatenation

Anonymous Functions

Insecure Code

SOQL query exposed to the browser

Insecure Code LWC
  • 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

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

6,344 total views, 18 views today

1 thought on “What’s wrong with my JavaScript Code”

Leave a Comment