Last active
May 13, 2023 16:08
-
-
Save NAZIMUDHEEN267/4e5da780a084c20d1dd6a2903d5f72e3 to your computer and use it in GitHub Desktop.
shortcuts && simple methods
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
1. | |
// !! double exclamation it returns boolean value true/false | |
const array = [0, 1, 2, 3, 0]; | |
array.filter(num => num > 0); // bad | |
array.filter(num => !!num); // good | |
2. | |
// It checks first condition is true or not then only move on to the second condition, if both condition is fullfilling then | |
// the object spread operator to the parent object | |
const obj = { name: 'Jhon' } | |
if(obj.name === 'jhon') { // bad | |
obj.age = 29; | |
} | |
const obj = { // good | |
name: 'Jhon', | |
...(this.name === 'Jhon' && { age: 29 } | |
}; | |
3. | |
// Swap using array destructure method | |
let a = 2, b = 1, temp; | |
temp = a; | |
a = b; | |
b = temp; // bad | |
[a, b] = [b, a]; // good | |
4. | |
// change the data type using Unary operator | |
let value = '1234'; | |
parseInt(value); // bad | |
+value //good |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment