【问题标题】:Is this an arrow function declaration? Is there such a thing?这是一个箭头函数声明吗?有这样的事吗?
【发布时间】:2020-12-07 14:16:44
【问题描述】:

我正在研究函数表达式与使用箭头函数的函数声明。

我认为这是一个箭头函数表达式:

const johan = greeting = () => {
  console.log("Hi from arrow function expression");
};

这是一个箭头函数 decleration:

 ludwig = () => {
  console.log("Hi from arrow function declaration");
};

正确吗?或者也许没有箭头函数声明之类的东西? 也许只有箭头函数表达式?

如果是这样,当我将命名箭头函数表达式放入另一个变量时,它会调用什么?

很高兴得到任何答案! :)

【问题讨论】:

  • 两者是一回事。 ludwig 恰好在前面定义过,有 varlet,或者可能都没有
  • 请注意,const johan = greeting = 42 也是有效的 - 它只是为两个变量分配了相同的值。
  • 或者可能没有箭头函数声明正确,没有箭头函数声明。箭头函数仅用于表达式。
  • 非常感谢!非常感谢!

标签: javascript arrow-functions function-declaration function-expression


【解决方案1】:

没有。

有函数声明、函数表达式和箭头函数(创建它们的语法也是表达式)。

(还有method declarations可以use arrow functions。)

ludwig = () => {
  console.log("Hi from arrow function declaration");
};

这是为变量赋值(箭头函数)。

变量声明丢失,所以要么它出现得更早,要么这会创建一个隐式全局(这在严格模式下是被禁止的)。

【讨论】:

  • 非常有趣(关于严格模式),感谢您的回答和链接,将阅读它们!感谢大家的回答!
猜你喜欢
  • 2017-11-30
  • 2017-03-17
  • 1970-01-01
  • 2018-08-23
  • 1970-01-01
  • 1970-01-01
  • 2010-10-07
  • 2019-07-01
  • 1970-01-01
相关资源
最近更新 更多