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
| console.log(+'100'); // 100 | |
| console.log(+null); // 0 | |
| console.log(+void 0); // NaN | |
| console.log(+true); // 1 | |
| console.log(+false); // 0 | |
| console.log(+[]); // 0 | |
| console.log(+[100]); // 100 |
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
| console.log(100 + ''); // "100" | |
| console.log(null + ''); // "null" | |
| console.log(void 0 + ''); // "undefined" | |
| console.log(true + ''); // "true" | |
| console.log(false + ''); // "false" | |
| console.log([] + ''); // "" | |
| console.log([100] + ''); // "100" |
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
| // METHOD 1: Using if/else statements | |
| if (loggedIn) { | |
| showUserProfile(); | |
| } else { | |
| showLoginForm(); | |
| } | |
| // METHOD 2: Using ternary operation | |
| loggedIn ? showUserProfile() : showLoginForm(); |
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 MIN_VALUE = 1; | |
| var MAX_VALUE = 5; | |
| /** | |
| * boundedValue(val) | |
| * | |
| * Returns val if val between MIN_VALUE and MAX_VALUE both inclusive | |
| * | |
| * Otherwise, returns MIN_VALUE if val is less than MIN_VALUE | |
| * |
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 randomInteger(maxvalue) { | |
| return 1 + Math.floor(Math.random() * maxvalue); | |
| } |
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 MIN_VALUE = 1; | |
| var MAX_VALUE = 5; | |
| /** | |
| * boundedValue(val) | |
| * | |
| * Returns val if val between MIN_VALUE and MAX_VALUE both inclusive | |
| * | |
| * Otherwise, returns MIN_VALUE if val is less than MIN_VALUE | |
| * |
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 leftZeroPad(value, maxlength) { | |
| while (value.length < maxlength) { | |
| value = '0' + value; | |
| } | |
| return value; | |
| } | |
| function boundedValue(minvalue, maxvalue) { | |
| return function(value) { | |
| return Math.max(minvalue, Math.min(maxvalue, +value || 0)); |
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
| $('#button').on('click', function(evt) { | |
| evt.preventDefault(); | |
| var content = $('<h1>Random Post Title</h1><p>Random post text.</p>'); | |
| $('#element').append(content); | |
| }); |
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
| class MyComponent extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.toggleInputCase = this.toggleInputCase.bind(this); | |
| this.state = { uppercase: false }; | |
| } | |
| toggleInputCase() { | |
| const isUpper = this.state.uppercase; |
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
| class MyComponent extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.toggleInputCase = this.toggleInputCase.bind(this); | |
| this.state = { uppercase: false }; | |
| } | |
| toggleInputCase() { | |
| const isUpper = this.state.uppercase; |