Skip to content

Instantly share code, notes, and snippets.

@NAZIMUDHEEN267
Last active May 13, 2023 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NAZIMUDHEEN267/4e5da780a084c20d1dd6a2903d5f72e3 to your computer and use it in GitHub Desktop.
Save NAZIMUDHEEN267/4e5da780a084c20d1dd6a2903d5f72e3 to your computer and use it in GitHub Desktop.
shortcuts && simple methods
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