javascript - 需要澄清为什么代码是正确的

标签 javascript typeof

const isString = (a, b, c) => {
  if (((typeof a) == "string") && ((typeof b) == "string") && ((typeof c) == "string")) {
    return "strings";
  }
  return "not strings";
}

为什么需要在参数之后的 => 才能使其工作?我通过反复试验得到了正确的测试问题,但我不明白为什么没有 => 就无法工作。

这里是说明。

Create a function called "isString" that takes 3 arguments (x1, x2, x3)

  • Check if each argument is a string using typeof.
  • If each argument is a string, return "strings".
  • If each argument is NOT a string, return "not strings".

最佳答案

=> 是箭头函数的语法

关于javascript - 需要澄清为什么代码是正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70149286/

相关文章:

javascript - 带有比较运算符的 bool 表达式的类型

javascript - 检查对象属性和调用方法的更好方法

javascript - 如何让我的 API 请求获取更新的数据库?

javascript - 如何使用 Javascript 查找图像上是否有标题

javascript - 从 2 个对象数组中获取缺失的对象

Javascript:获取尽可能高的UTF8字符

angular - 如何在 Angular 数据类型上使用 ngSwitch?

javascript - 在 Modal 的子组件中设置时,不会触发 BackAndroid/BackHandler 事件监听器

c# - 遍历类和子类以在 C# 中检索属性和值

javascript - 检查 JavaScript 函数是否是 jQuery 元素的方法