JS交换两个变量的值

方法一:

传统普通的方法,新增一个中间变量

	let c = 0;
 	let d = 1;
    let temp = null;
    temp = c;
    c = d;
    d = temp;

方法二:

	let a = {
        name:"刘"
    };
    let b = {
        name:"熊芮大美女"
    };
    [b,a] = [a,b]

方法三:

纯装逼写法,适用于数值,用异或的方法,异或是啥?自己百度

 	let a = 1;
    let b = 2;
    a = a ^ b;
    b = a ^ b;
    a = a ^ b;

你可能感兴趣的:(javascript)