意外输出 javascript [重复]

问题描述 投票:0回答:1

let player1 = "bbbb"
let player2 = "aaaa"
let value1 = 10
let value2 = 20

if (player1 > player2) {
  [player1, player2] = [player2, player1]
  [value1, value2] = [value2, value1]
}

console.log(player1, player2, value1, value2)

//real output: 20 10 10 20
//expected output: aaaa bbbb 20 10

我正在尝试反转变量值以按字母顺序对它们进行排序,但我得到了意外的输出\

我想反转变量的值

javascript sorting variables
1个回答
-1
投票

只需在每个语句末尾添加

;

© www.soinside.com 2019 - 2024. All rights reserved.