Skip to content

Instantly share code, notes, and snippets.

@qodirovshohijahon
Created January 13, 2020 13:30
Show Gist options
  • Save qodirovshohijahon/92a4e6031259e3c411c8440efe816c66 to your computer and use it in GitHub Desktop.
Save qodirovshohijahon/92a4e6031259e3c411c8440efe816c66 to your computer and use it in GitHub Desktop.
In this example you will see swapping in js.
function swappingUsingTwoVars(num1, num2) {
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
return ("First number " + num1 + "\nSecond number " + num2);
}
@qodirovshohijahon
Copy link
Author

It is the worst way of swapping coz it will be limitation in number's value that is number type may contain 2^32 in this ex 2^32 adding 2^32 that means wrong.But this is also method of swapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment