简体   繁体   English

错误:预期分配或函数调用,而是看到一个表达式

[英]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.

相关问题 期望赋值或函数调用,但在函数中看到表达式错误 - Expected an assignment or function call and instead saw an expression error in function 期望赋值或函数调用,而是看到了一个表达式 - Expected an assignment or function call and instead saw an expression 期望一个赋值或函数调用,而是看到一个表达式? - Expected an assignment or function call and instead saw an expression? 期望一个赋值或函数调用,而是看到一个表达式 - Expected an assignment or function call and instead saw an expression 错误-预期分配或函数调用,而是看到一个表达式 - Error - Expected an assignment or function call and instead saw an expression ReactJS错误:“预期分配或函数调用,而是看到了一个表达式” - ReactJS error: “Expected an assignment or function call and instead saw an expression” React Error Expected an assignment or function call 而是看到一个表达式 - React Error Expected an assignment or function call and instead saw an expression 反应错误 [期望赋值或函数调用,而是看到一个表达式] - React error [Expected an assignment or function call and instead saw an expression] 语法错误(预期分配或函数调用,而是看到一个表达式) - Syntax Error (Expected an assignment or function call and instead saw an expression) 错误预期分配或函数调用,而是看到一个表达式 - Error-Expected an assignment or function call and instead saw an expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM