Ad
Ad
Ad
Lightning Web Components

Basic javaScript concepts before deep diving into Lightning Web Components

Pinterest LinkedIn Tumblr

 Basic javaScript concepts before deep diving into Lightning Web Components

In this post, We will try to understand Basic Javascript concepts that will help us in learning Lightning Web Components.

1.Case Sensitivity:  If you are coming from World of Salesforce/Apex then the first key thing to remember is JavaScript is Case Sensitive. For Example, the word “Salesforce” and “salesforce” are treated differently in javascript.

2. DOM(Document Object Model) :  Whenever we visit any website page, the browser creates a Document object model for the page. The browser that we use to view the website is a program that interprets HTML and CSS and renders the style, content, and structure into the page that you see. This is constructed/represented as a tree of objects. This DOM could update any element on the page by accessing this document.

3. Variable Declaration: We can use let, var, const for variable declaration in Javascript. Always use let and const for variable declaration. Do remember we can assign objects and functions to variables, unlike other programming languages.

Ex: let myName=’SfdcLightning’; // We can change the value of myName whenever required in the code

let account = new Account(); // We can change the value of Account whenever required in the code

const  value =5; // This value is Permanent and cannot be changed in the code.

const car = new car();//The value of car cannot be changed but we can change the properties inside  the car

4. Functions:  In JavaScript, everything is an Object. Functions can be assigned to variables, passed into parameters of other functions.

function name(parameter1, parameter2, parameter3) {

//Write any code that needs to be executed

}

Ex: var cal = myCalculation(4, 3);  //Cal will give us the value as 12

function myCalculation(a, b) {

return a * b;         // Function returns the product of a and b

}

5.JavaScript Data Types: There are different data types that hold Values/Objects.

There are 5 different  data types that contains values(String/number/boolean/object/function).

There are also 6 types of objects (Object/Date/Array/String/Number/Boolean).

Two datatypes cannot contain values (null/undefined).

6. this keyword: Learn about this keyword as it differs from Apex in salesforce. There are various scenarios and behavior changes of this keyword unlike in apex where it is confined to the current instance of that particular class. Learn more about the use-cases

https://www.w3schools.com/js/js_this.asp

Write A Comment