Skip to main content

Write a program to swap two numbers using third variable in JavaScript.

 Swap two numbers using third variable in JavaScript.

var a =8, b= 17, temp; //a = 8, b = 17

temp = a;

a=b;

b = temp;

document.write("a = "+a+", b = "+b);

Output:

a = 17, b = 8



Is this snippet helpful? please comment below

Comments