如何在箭头函数中添加if语句

Mat*_*rot 3 javascript arrow-functions

我是 JS 的初学者,想知道带有 if 语句的箭头函数和常规函数(例如 function)的语法是什么

\n
getStringLength(string){\n  let stringLength;\n  if (string.length === 1){\n     stringLength = `La cha\xc3\xaene contient qu'un seul caract\xc3\xa8re`;\n  } else {\n     stringLength = `La cha\xc3\xaene contient ${string.length} caract\xc3\xa8res`;\n  }\n     return stringLength;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

小智 7

那将是

\n
const getStringLength = (string) => {\n  let stringLength;\n    if (string.length === 1){\n            stringLength = `La cha\xc3\xaene contient qu'un seul caract\xc3\xa8re`;\n    } else {\n            stringLength = `La cha\xc3\xaene contient ${string.length} caract\xc3\xa8res`;\n    }\n    return stringLength;\n}\n
Run Code Online (Sandbox Code Playgroud)\n