[英]Error: expected an assignment or function call and instead saw an expression
booking.save(function (error, data) {
error ? console.log(error) : res.redirect('/');
});
This code is causing the following error to be displayed in Sublime Text: 此代码导致在Sublime Text中显示以下错误:
Expected an assignment or function call and instead saw an expression
Why is that? 这是为什么? What is wrong with my code?
我的代码有什么问题? It's working 100%.
它正在工作100%。 I don't see the error.
我没有看到错误。
It is JSLint error not JS error. 这是JSLint错误而不是JS错误。
In your case it considers that ternary operators should been used only for assignment such as 在您的情况下,它考虑仅将三元运算符用于赋值,例如
var foo = bar ? 2 : 3;
since there is no assignmet JSLint consider that string useless. 因为没有指定方法JSLint认为该字符串无用。 Change it to
if-else
block or use JSHint with proper settings instead. 将其更改为
if-else
块或使用具有适当设置的JSHint代替。
It expects the body of a function to be a list of statements. 它期望函数的主体为语句列表。 JSLint throws this warning because
JSLint发出此警告是因为
error ? console.log(error) : res.redirect('/');
is an expession, not a statement. 是一种支出,不是陈述。 To make the warning go away, use an
if...else
statement instead. 要使警告消失,请改用
if...else
语句。
if(err) console.log(error);
else res.redirect('/');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.