This file contains hidden or 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
var randomBoolean = Math.random() >= 0.5; |
This file contains hidden or 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
function dayInYear(date){ | |
return Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24); | |
} | |
dayInYear(new Date()); // 12 |
This file contains hidden or 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
/* | |
SAMPLE HTML | |
<div class="demo-grid"> | |
<div class="demo-card"> | |
<img width="200" height="200" src="https://placekitten.com/200/200?image=1" alt="" class="demo-img"> | |
<h1 class="line-clamp demo-title"> | |
Spill litter box, scratch at owner, destroy all furniture, especially couch | |
</h1> | |
</div> |
This file contains hidden or 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
Object.keys(myObject).length; |
This file contains hidden or 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
let array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
console.log(array.slice(-1)); // Result: [9] | |
console.log(array.slice(-2)); // Result: [8, 9] | |
console.log(array.slice(-3)); // Result: [7, 8, 9] |
This file contains hidden or 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
let array = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; | |
array = array.slice( 0, 4 ); | |
console.log( array ); // Result: [0, 1, 2, 3] | |
// OR | |
let array = [0, 1, 2, 3, 4, 5, 6, 6, 8, 9] | |
array.length = 4 |
This file contains hidden or 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
// NUMBER TO STRING | |
//========================== | |
const val = 1 + ''; | |
console.log( val ); // Result: "1" | |
console.log( typeof val ); // Result: "string" | |
// STRING TO NUMBER | |
//========================== | |
let int = '15'; |
This file contains hidden or 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
// If you know multiple values | |
const items = ['a', 'b', 'c', 'd', 'e', 'f']; | |
const valuesToRemove = [ 'c', 'd' ]; | |
const filteredItems = items.filter(( item ) => !valuesToRemove.includes( item )); | |
// ["a", "b", "e", "f"] | |
This file contains hidden or 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
const PromiseArray = [ | |
Promise.resolve(100), | |
Promise.reject(null), | |
Promise.resolve("Data release"), | |
Promise.reject(new Error('Something went wrong'))]; | |
Promise.all(PromiseArray) | |
.then(data => console.log('all resolved! here are the resolve values:', data)) | |
.catch(err => console.log('got rejected! reason:', err)) |
This file contains hidden or 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
[0, 10, 4, 9, 123, 54, 1].sort((a, b) => a - b); | |
>>> [0, 1, 4, 9, 10, 54, 123] |