react js default variables code example
Example 1: default props react
// ES6 class
class CatComponent extends React.Component {
constructor(props) {}
render() {
return <div>{this.props.catName} Cat,
Eye Color: {this.props.eyeColor },
Age: {this.props.age}</div>
}
}
CatComponent.defaultProps = {
catName: "Sandy",
eyeColor: "deepblue",
age: "120"
}
Example 2: javascript default function parameter value
function multiply(a, b) {
b = (typeof b !== 'undefined') ? b : 1
return a * b
}