6 Tricks To Writeless Java Script
1. TERNARY OPERATOR
Longhand :cons, num = 20; let answer;
it (x > 10) { answer = "greater than 10"; 1 else f answer = "less than 10";
Shorthand :
answer = > ? .greater than 10" : "less than 10";
2. DECLARING VARIABLES
Longhand :let vegies; let fastFood; let fruits = 'Apple',
Shorthand :
vegies, fastFood, fruits = 'Apple';
3. IMPLICIT RETURN
Longhand :function calcCircumference(diameter) { return Math.PI * diameter; }
Shorthand :
calcCircumference = diameter => Math.PI * diameter;
4. MULTILINE STRING
Longhand :lorem = 'Lorem ipsum dolor sit amet,\n\t' + 'adipisicing elit, sed do eiusmod tempor\n\t' + 'nisi ut aliquip ex ea commodo consequat.\n\t';
Shorthand :
lorem = 'Lorem ipsum dolor sit amet, adipisicing elit,sed do eiusmod tempor nisi ut aliquip ex ea commodo consequat.';
5. ARROW FUNCTIONS
Longhand :functioH sayHello(name) console.Loy('Hello', 1
list.forEach(functio (item) console. log( item); 1);
Shorthand :
sayHello = name => console.log('Hello., name);
list.forEach(item => console.log(item));
6. TEMPLATE LITERALS
Longhand :welcome = 'Welcome ' +first+ +last+ ...;
db = 'http://' +host+ ':' +port+ '/' +database;
Shorthand :
const welcome = 'Welcome ${ first} WastY;
const db = 'http://${ }:${port}/${database}';
6 Tricks To Writeless Java Script
Reviewed by Farhan
on
8:55 PM
Rating:
No comments: