swap two variable in javascript program | javascript #coding #javascript

swap two variable in javascript program | javascript #coding #javascript

codewithsekar

1 год назад

4,001 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

hdgamer1404Jonas
hdgamer1404Jonas - 08.09.2022 19:34

You could at least put it into a function and you forgot to document your code 💢

Ответить
Khanh Khuu
Khanh Khuu - 08.09.2022 19:26

let a = 10;
let b = 20;
[a, b] = [b, a];
console.log(a);
console.log(b);

Ответить
DO462
DO462 - 08.09.2022 19:04

In case anyone is interested in to swap variables without declaring any temp variable, you can write:
a = a + b;
b = a - b;
a = a - b;
At the end, variables have swapped

Ответить