Friday, January 6, 2023

JavaScript Basics, Operators and Conditional Statements for Salesforce

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
JavaScript Basics -
javaScript can be used for -
Front End Applications -
Angular JS ...
Back End Applications -
Node JS
javaScript works for both Mobile and Web Apps
ES6 (2015) onwards new version introduced for every year. (ES6 Major update to JavaScript)
To include in the html or visualforce -
<script src="script.js"></script>
Shortcut to open the javaScript console -
Option + Command + j in Mac
Ctrl + Alt + J in Windows
console.log('print here'); // to print in the javaScript console
JavaScript Data Types -
1. Number
2. String
3. Boolean
4. Undefined
5. Null
6. Symbol
7. Bigint
Operators -
const num = 2;
console.log(num + 2, num - 2, num / 2, num ** 3);
const firstName = 'Srinu', lastName = 'SFDC';
console.log(firstName + ' ' + lastName);
// Templace Strings
console.log(`${firstName} ${lastName}`);
== and ===
falsy values: 0, '', undefined, null, NAN
console.log(Boolean(0));
// Assignment Operator -
let num = 5;
// Arthematic Operators
// Unary Operator
num++;
console.log('num: '+num);
// Binary Operator
console.log(num + 5 - (8 - 7), num - 5, num * 5, num / 5, num ** 3);
// Ternary Operator
// Stmt
num > 0 ? console.log('num is > 0') : console.log('num is < 0');
// expression
num = 'num is ' + (num > 0 ? '> 0' : '< 0');
console.log('num: '+num);
Type Conversion and Coercion -
// type coversion
console.log(Number('20')+5);
console.log(Number('test')); //NAN
console.log(String(10));
// automatic type coercion
console.log('I am having ' + 15 + ' certifications ' ); // number will be converted to text , + operator to alway number
console.log('20'-'10');
console.log('20'/'10');
console.log('20'>'10');
conditional statement -
if() {}
else {}
----------------
Only equality -
===============
let day = 'Wedensday';
switch(day) {
case 'Sunday':
console.log(`This is Sunday`);
case 'Monday':
console.log(`This is Monday`);
case 'Tuesday':
console.log(`This is Tuesday`);
break;
case 'Wednesday':
case 'Thrusday':
console.log(`This is Wednesday or Thrusday`);
break;
case 'Friday':
console.log(`This is Friday`);
break;
case 'Saturday':
console.log(`This is Saturday`);
break;
default:
console.log(`Invalid Day`);
}

No comments:

Post a Comment

Understanding Wire vs Imperative Apex Method Calls in Salesforce Lightning Web Components (LWC)

Understanding Wire vs Imperative Apex Method Calls in Salesforce Lightning Web Components (LWC) Introduction: Salesforce Lightning Web ...