Live Salesforce Training & Pre-Recorded Videos Available | Admin • Development • LWC • Agentforce • Data 360 • Integration • Job-Ready Sessions | Contact us for more info +91 - 709 7777 111
Welcome to SfdcIndia

Javascript for LWC

Gallery Feature

About JavaScript

Core JavaScript for Salesforce & LWC Developers

This guide contains only the essential JavaScript concepts required before learning Salesforce Lightning Web Components.

1. Variables

Use const by default and let when the value needs to change.
Example:
const company = 'SFDCINDIA';
let course = 'LWC';

2. Data Types

Important JavaScript data types:

  • String
  • Number
  • Boolean
  • Undefined
  • Null
  • Object
  • Array

3. Operators

Core operators:
Best practice: prefer === instead of ==.

  • Arithmetic: + - * / %
  • Comparison: > < >= <=
  • Equality: === and !==
  • Logical: && || !

4. Conditions

Use:
These control which logic should run based on a condition.

  • if
  • else if
  • else
  • switch
  • ternary operator

5. Loops

Important loops:
for...of is useful when reading array values.

  • for
  • while
  • for...of

6. Functions

Understand:
Arrow functions are very common in modern JavaScript and Salesforce LWC.

  • Normal functions
  • Arrow functions
  • Parameters
  • Return values

7. Strings

Useful String methods:

  • length
  • toUpperCase()
  • toLowerCase()
  • includes()
  • replace()
  • slice()
  • trim()

8. Arrays

Important Array concepts:
These are extremely important for handling Salesforce record collections.

  • Accessing values
  • push()
  • pop()
  • forEach()
  • map()
  • filter()
  • find()
  • reduce()

9. Objects

Objects store data as key-value pairs.
Important skills:
Salesforce records are commonly handled as JavaScript objects in LWC.

  • Read properties
  • Update properties
  • Add new properties
  • Work with nested objects

10. Destructuring

Destructuring extracts values from arrays or objects.
This makes JavaScript code shorter and cleaner when working with Salesforce data.

11. Spread Operator

The spread operator (...) is very important in LWC.
Common uses:

  • Copy arrays
  • Copy objects
  • Add new values
  • Update one property while preserving other properties

12. Optional Chaining

Optional chaining uses ?.
Example concept:
account.owner?.name
It helps avoid errors when a nested value may not exist.

13. Classes

JavaScript classes contain properties and methods.
Salesforce connection:
Every Lightning Web Component class extends LightningElement.

14. Scope

Understand:
let and const use block scope.

  • Global scope
  • Function scope
  • Block scope

15. Callbacks

A callback is a function passed to another function.
Array methods such as map(), filter() and forEach() use callbacks.

16. Promises

Promises represent asynchronous results.
Main states:
Promises are important when working with asynchronous Salesforce operations.

  • Pending
  • Fulfilled
  • Rejected

17. async and await

async/await makes asynchronous JavaScript easier to read.
Common LWC pattern:

  • Call Apex
  • Wait for response
  • Store returned data
  • Handle errors

18. Error Handling

Use try and catch to handle errors safely.
This is important when calling Apex or working with asynchronous code.

19. JSON

Important JSON methods:
JSON is heavily used in Salesforce integrations and API communication.

  • JSON.stringify()
  • JSON.parse()

20. Events

Understand:
Events are fundamental in LWC user interactions.

  • Click events
  • Change events
  • Event object
  • event target value

21. Immutability

Instead of directly changing existing data, create a new array or object.
This is a good pattern for predictable LWC state updates.

22. Modules

JavaScript modules use import and export.
LWC uses module imports for framework features, Apex methods, schema references and other Salesforce resources.

Most Important for Salesforce LWC

  • Functions and Arrow Functions
  • Arrays and Objects
  • map(), filter(), find() and reduce()
  • Destructuring
  • Spread Operator
  • Promises
  • async / await
  • Events
  • JSON
  • Error Handling
SFDCINDIA — Salesforce Admin, Development, LWC, Integration, Agentforce and Data 360 Training.