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
var a =8, b= 17, temp; //a = 8, b = 17
temp = a;
a=b;
b = temp;
document.write("a = "+a+", b = "+b);
a = 17, b = 8
Is this snippet helpful? please comment below
Comments
Post a Comment