Advertisement
Guest User

Swapping two variables with only two variables

a guest
Nov 13th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //first we define our variables
  2. var a = "programmer"
  3. var b = "humor"
  4.  
  5. //then put them both in a
  6. var a = a + "_" + b
  7. //then assign the part before the separator to b
  8. var b = a.split("_")[0]
  9. //lastly assign tje part after the separator to a
  10. var a = a.split("_")[1]
  11.  
  12. //then we just output them to the document
  13. document.write("Var A: " + a + "<br> Var B: " + b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement