An arrow function can simply be seen as a concise version of a regular function, except that the return
is implied (among a few other subtle things you can read about here). One nice way to use an if/else is though a ternary. Take this regular function:
function(a){
if(a < 10){
return 'valid';
}else{
return 'invalid';
}
}
The equivalent in an arrow function using a ternary is:
a => (a < 10) ? 'valid' : 'invalid'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…