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
| 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
| 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
| 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
| /* | |
| 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
| 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
| 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
| let method = (/* True or false */ ? 'start' : 'stop'); | |
| array[method](); |
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 serializeForm = form => | |
| Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&'); | |
| serializeForm(document.querySelector('form') | |
| // full-name=Adrian%20Legaspi&email=adrian.luball%40gmail.com&nickname=ImLuyou |
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 formToObject = form => | |
| Array.from(new FormData(form)).reduce( | |
| (acc, [key, value]) => ({ | |
| ...acc, | |
| [key]: value | |
| }), | |
| {} | |
| ); | |
| formToObject(document.querySelector('form'); |