Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript swap two variables

[a, b] = [b, a];
Comment

javascript Swapping Variables

// program to swap variables

let x = 4;
let y = 7;

// swapping variables
[x, y] = [y, x];

console.log(x); // 7
console.log(y); // 4
Comment

swap two variables javascript

var a = 1,
    b = 2;
b = [a, a = b][0];
Comment

javascript swap variables

var a = 5;
var b = 3;
[a, b] = [b, a];
Comment

Swapping variables JS

let a = 1;
let b = 3;

[a, b] = [b, a];
console.log(a); // 3
console.log(b); // 1

const arr = [1,2,3];
[arr[2], arr[1]] = [arr[1], arr[2]];
console.log(arr); // [1,3,2]
Comment

how do you swap the vaRIables js

let a = "red";
let b = "blue";
let c = a; // red
a = b; //over-rides to blue
b = c;

console.log(a);
console.log(b);
Comment

PREVIOUS NEXT
Code Example
Javascript :: document.elementsFromPoint 
Javascript :: return multiple native element react native 
Javascript :: xmlhttprequest set route params 
Javascript :: hide parent component when child component loaded 
Javascript :: js find :invalid inside div 
Javascript :: diable input javascript 
Javascript :: angular table lazy loading 
Javascript :: github react hardhat nft marketplace application 
Javascript :: fetchapi snippet 
Javascript :: cantsee auto complete for node jsmodules in vs code 
Javascript :: parse int stackoverflow 
Javascript :: como acrescentar item no array js 
Javascript :: how to remove elevation tab bar react native 
Javascript :: angular data table push not working 
Javascript :: random height fallling object in js 
Javascript :: how to set up click event listeners javascript 
Javascript :: Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse 
Javascript :: what is x path js 
Javascript :: jquery set radio button checked 
Javascript :: sessionStorage on DOMContentLoaded javascript 
Javascript :: Audio Stream from Server through Scoket 
Javascript :: how to replace import with require 
Javascript :: change active menu item on page scroll javascript 
Javascript :: Javascript multiplier function 
Javascript :: javascript find the smallest and biggest number in array 
Javascript :: stack overflow javascript tree 
Javascript :: redux extension link 
Javascript :: how to put value in arrar 
Javascript :: what is fn extend 
Javascript :: H.C.F Calculation Program 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =