→ Use ~~ to quickly trim the decimal part in a number
~~25.2 => 25 ↓
→ Filter falsy values quickly const arr = [1, 0, 2, '', 3, null, 4]; const filtered = arr.filter(Boolean); // filtered: [1, 2, 3, 4]
→ Convert a string to a number type
→ Filter falsy values quickly const arr = [1, 0, 2, '', 3, null, 4]; const filtered = arr.filter(Boolean); // filtered: [1, 2, 3, 4]
→ Convert a string to a number type
const years = '17';
const age = +years;
// years: '17'
// age: 17
→ Convert a value to a boolean type
→ Convert a value to a boolean type
const isPresent = 'yes';
!!isPresent; // true
For more tricks check this full article with 10 interesting JavaScript tricks
For more tricks check this full article with 10 interesting JavaScript tricks
No comments:
Post a Comment
If you have any doubts or questions, please let us know.