๐—ฆ๐˜„๐—ฎ๐—ฝ ๐—ง๐˜„๐—ผ ๐—ก๐˜‚๐—บ๐—ฏ๐—ฒ๐—ฟ๐˜€ ๐—ช๐—ถ๐˜๐—ต๐—ผ๐˜‚๐˜ ๐—” ๐—ง๐—ต๐—ถ๐—ฟ๐—ฑ ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ

You want to swap two variables. Most people use a third variable. You do not need one.

Here are four ways to do it.

Method 1: Temporary Variable

Method 2: Addition and Subtraction

Method 3: Destructuring

Method 4: Bitwise XOR

Pick the one you need for your project.

Source: https://dev.to/raja_b_0c9d242e2c26cf063b/swap-two-numbers-without-using-a-third-variable-1hje