Javascript 将花括号添加到fat arrow函数会破坏它

Javascript 将花括号添加到fat arrow函数会破坏它,javascript,arrays,typescript,ecmascript-6,Javascript,Arrays,Typescript,Ecmascript 6,有谁能解释一下为什么会这样: filteredArray = contacts.filter( (contact: Contact) => contact.name.toLowerCase().includes(term.toLowerCase()) ); 但事实并非如此: filteredArray = contacts.filter((contact: Contact) => { contact.name.toLocaleLowerCase().includes(ter

有谁能解释一下为什么会这样:

filteredArray = contacts.filter(
  (contact: Contact) => contact.name.toLowerCase().includes(term.toLowerCase())
);
但事实并非如此:

filteredArray = contacts.filter((contact: Contact) => {
  contact.name.toLocaleLowerCase().includes(term.toLocaleLowerCase());
});

我不明白为什么仅仅在这里添加大括号似乎就可以打破这一局面。

如果您使用大括号,那么您必须使用
return
关键字。单行语句不需要大括号:

filteredArray = contacts.filter((contact: Contact) => {
  return contact.name.toLocaleLowerCase().includes(term.toLocaleLowerCase());
});

@姆博伊科我想那是错误的复制品