How to swap two variables in one line in TypeScript

1 Answer

0 votes
let a: number = 3;
let b: number = 7;
 
[a, b] = [b, a];
 
 
console.log(a);
console.log(b);
 
  
  
  
  
/*
run:
  
7
3
  
*/

 



answered Oct 31, 2021 by avibootz

Related questions

1 answer 230 views
1 answer 185 views
1 answer 210 views
1 answer 286 views
...