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.inputField = React.createRef(); | |
this.toggleInputCase = this.toggleInputCase.bind(this); | |
this.state = { uppercase: false }; | |
} | |
toggleInputCase() { |
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 FormInput extends React.Component { | |
constructor(props) { | |
super(props); | |
this.textInput = React.createRef(); | |
} | |
hasText() { | |
return this.textInput.current.value.length > 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
const MyComponent = (props) => { | |
const formInput = React.createRef(); | |
const inputSelection = () => { | |
const input = formInput.current; | |
if (input.hasText()) { | |
input.selectInputText(); | |
} |
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 ControlledFormInput extends React.Component { | |
constructor(props) { | |
super(props); | |
this.handleChange = this.handleChange.bind(this); | |
this.state = { value: "Glad" }; | |
} | |
handleChange(evt) { | |
this.setState({ value: evt.target.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
class UncontrolledFormInput extends React.Component { | |
constructor(props) { | |
super(props); | |
this.inputField = React.createRef(); | |
this.handleChange = this.handleChange.bind(this); | |
this.state = { value: "Glad" }; | |
} | |
handleChange(evt) { | |
this.setState({ value: this.inputField.current.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
// MORE THAN ONE ARGUMENTS: | |
// Creates a new array with the arguments as items. | |
// The length of the array is set to the number of arguments. | |
var array1 = new Array(1, 2, 3); | |
console.log(array1); // [1, 2, 3] | |
console.log(array1.length); // 3 | |
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
/** | |
* range() | |
* | |
* Returns an array of numbers between a start number and an end number incremented | |
* sequentially by a fixed number(step), beginning with either the start number or | |
* the end number depending on which is greater. | |
* | |
* @param {number} start (Required: The start number.) | |
* @param {number} end (Required: The end number. If end is less than start, | |
* then the range begins with end instead of start and decrements instead of increment.) |
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 greeting = `Good morning!`; | |
const shortcut = `\`cmd\` + \`shift\` + \`G\``; | |
console.log(greeting); // "Good morning!" | |
console.log(shortcut); // "`cmd` + `shift` + `G`" |
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 message = "Hello Glad, \ | |
Your meeting is scheduled for noon today."; | |
console.log(message); | |
// Hello Glad, Your meeting is scheduled for noon today. |
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 message = "Hello Glad,\n\ | |
Your meeting is scheduled for noon today."; | |
console.log(message); | |
// Hello Glad, | |
// Your meeting is scheduled for noon today. |