swapping
Node.js
let a = 'foo'
let b = 'bar'
console.log(a, b);
[b, a] = [a, b]
console.log(a, b)
Output
foo bar
bar foo
Go
package main
import "fmt"
func main() {
a := "foo"
b := "bar"
fmt.Println(a, b)
b, a = a, b
fmt.Println(a, b)
}
Output
foo bar
bar foo
当前内容版权归 miguelmota 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 miguelmota .