Javascript 数错数字

Javascript 数错数字,javascript,node.js,if-statement,numbers,Javascript,Node.js,If Statement,Numbers,我遇到了一个奇怪的问题 我在服务器上保存了一个“当前正在运行”的剪辑,然后发送下一个或上一个剪辑的id,以确定是否需要向前或向后跳过 if ((request.command.substring(15) > device.currentClip)) { console.log("XXXXX command: " + request.command.substring(15)); console.log("XXXXX current clip

我遇到了一个奇怪的问题

我在服务器上保存了一个“当前正在运行”的剪辑,然后发送下一个或上一个剪辑的id,以确定是否需要向前或向后跳过

if ((request.command.substring(15) > device.currentClip)) {
            console.log("XXXXX command: " + request.command.substring(15));
            console.log("XXXXX current clip " + device.currentClip);
            console.log("[INFO] skipping forward (playlist)");
            return;
}  else if ((request.command.substring(15) < device.currentClip)) {
            console.log("XXXXX command: " + request.command.substring(15));
            console.log("XXXXX current clip " + device.currentClip);
            console.log("[INFO] skipping backward (playlist)");
            return;
}
有人能解释一下(可能的)错误吗?

substring()
返回一个字符串,字符串的比较是通过逐字符比较来完成的,因此:

  • “10”<“9”,以及
  • “10”<“11”
您可以使用
parseInt
功能,将两侧转换为
int
(如果
device.currentClip
已经是
int
,则不需要再进行转换):


您还可以在引号之间打印整个
request.command
console.log(“““+request.command+””)?也许您在某个地方有触发行为的空间。使用request.command更新控制台输出
'goto: clip id: 12'
XXXXX command: 12
XXXXX current clip 11
[INFO] skipping forward (playlist)
'goto: clip id: 10'
XXXXX command: 10
XXXXX current clip 9
[INFO] skipping backward (playlist)
var intCommand = parseInt(request.command.substring(15), 10);
var intCurrentClip = parseInt(device.currentClip);
if (intCommand > intCurrentClip)) {
// the rest of the code