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 in javascript

var first = 5;
var second = 7;
[first, second] = [second, first];
console.log(first, second);
//answer - 7 5
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 :: javascript 2 return values 
Javascript :: javascript get nested element 
Javascript :: filter repetition 2d array javascript 
Javascript :: jquery import js file 
Javascript :: turnery opertaor js 
Javascript :: clear the command prompt node 
Javascript :: js string methods 
Javascript :: js fibonacci sequence 
Javascript :: polyfill for bind 
Javascript :: map array method create object 
Javascript :: axios cnd 
Javascript :: sequelize migration 
Javascript :: Pass Props to a Component Using defaultProps in react 
Javascript :: remove object from array by name javascript 
Javascript :: string number to array 
Javascript :: milliseconds to date javascript 
Javascript :: p5js import typescript 
Javascript :: jquery show hide based on data attribute 
Javascript :: react native inline style 
Javascript :: set background image URL jQuery 
Javascript :: hide_node example jstree 
Javascript :: javascript get image dimensions 
Javascript :: how to change favicon dynamic in react js 
Javascript :: javascript mouse over and mouse enter 
Javascript :: add two numbers in javascript 
Javascript :: convert a string to number in javascript 
Javascript :: url query example 
Javascript :: status codes json 
Javascript :: object literal javascript 
Javascript :: jqeury input checkbox listener not working 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =