javascript / beginner
Snippet
String Length Validation
The .length property on strings is useful for checking the size of user input to provide immediate feedback in the user interface.
snippet.js
1
2
3
4
5
6
7
8
9
const PasswordHint = (props) => {const isTooShort = props.password.length < 8;return (<span>{isTooShort && "Password must be 8+ characters"}</span>);};
react
Breakdown
1
props.password.length < 8
Accesses the length property of the password string to compare it against the number 8.