DEV Community

Discussion on: How can you swap two variables without using a third?

Collapse
 
joelnet profile image
JavaScript Joel • Edited

You could use the K combinator to swap any value, not just numbers!

let a = "hello"
let b = "goodbye"

a = (x => () => x)(b)(b = a)

a // => "goodbye"
b // => "hello"