Skip to content

Commit d0e6c2c

Browse files
swapping value
1 parent 0bafb7b commit d0e6c2c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

swap.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//swap variables value
2+
3+
//process-1
4+
console.log("process-1");
5+
let numOne = 10;
6+
let numTwo = 20;
7+
console.log(`before : numOne : ${numOne} numTwo: ${numTwo}`);
8+
//before : numOne : 10 numTwo: 20
9+
let temp = numOne;
10+
numOne = numTwo;
11+
numTwo = temp;
12+
console.log(`after : numOne : ${numOne} numTwo: ${numTwo}`);
13+
//after : numOne : 20 numTwo: 10
14+
15+
//process-2
16+
console.log("process-2");
17+
let x = 20;
18+
let y = 30;
19+
console.log(`before: x : ${x} y: ${y}`);
20+
//before: x : 20 y: 30
21+
x = x + y;
22+
y = x - y;
23+
x = x - y;
24+
console.log(`after: x : ${x} y: ${y}`);
25+
//after: x : 30 y: 20
26+
27+
//process-3
28+
let a = 200;
29+
let b = 300;
30+
console.log("before:", a, b);
31+
[a, b] = [b, a];
32+
console.log("after:", a, b);

0 commit comments

Comments
 (0)