Learn Basic Algorithmic Thinking by Building a Number Sorter - Step 19-

i passed this step but i’m not sure i understand the first and third lines inside the for loop
can someone explane it to me

if (array[j] > array[j + 1]) {
        const temp = array[j];
        array[j] = array[j + 1];
        array[j + 1] = temp;
      }

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-basic-algorithmic-thinking-by-building-a-number-sorter/step-19

const arr = [1, 2]
const temp = arr[0] // temp is 1
arr[0] = arr[1] // now arr[0] is 2 while temp is still 1
arr[1] = temp // and now arr[1] is 1!
console.log(arr) // [2, 1]

you can use a tool like Online JavaScript Compiler, Visual Debugger, and AI Tutor - Learn JavaScript programming by visualizing code to see the code executed line by line

slighly more confusing but doesn’t use temp, there is also

[arr[0], arr[1]] = [arr[1], arr[0]]

thank u, the last example explaned it better to me