Mat*_*rot 3 javascript arrow-functions
我是 JS 的初学者,想知道带有 if 语句的箭头函数和常规函数(例如 function)的语法是什么
\ngetStringLength(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}\nRun Code Online (Sandbox Code Playgroud)\n
小智 7
那将是
\nconst 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}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1131 次 |
| 最近记录: |