nodejs:意外令牌“ <”

时间:2019-09-07 10:20:18

标签: javascript node.js syntax

我有这样的颂歌:

var i = 10;
if (i < 0 || i => 10) {
  console.log("Out of bounds!");
}

但是nodejs抛出以下错误:

if (i < 0 || i => 10) { console.log("Out of bounds!"); }
      ^
SyntaxError: Unexpected token <

1 个答案:

答案 0 :(得分:2)

问题不是<,而是第二个比较中的=>。这不是大于或等于比较运算符,而是用于定义函数的箭头运算符。 这会混淆nodejs,并引发错误。

请改用>=

if (i < 0 || i >= 10) { console.log("Out of bounds!"); }