Created
November 4, 2016 18:52
-
-
Save abhardwaj4/49ec34eb2d4fa167ff4d287590452128 to your computer and use it in GitHub Desktop.
Swapping two variables in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function swapUsingThirdVariable(a, b) { | |
var c = a; | |
a = b; | |
b = c; | |
} | |
function swapNumbersWithoutThirdVariable(a, b) { | |
a = a + b; | |
b = a - b; | |
a = a - b; | |
} | |
function swapUsingES6Destructuring(a, b) { | |
[a, b] = [b, a]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment