What does "cd && cd -" do on Mac OS terminal?

Hey fellow computer geeks,

I came across this snippet of code on the Mac OS terminal:

cd && cd -

What does it mean?


cd returns to the home directory

&& lets you do something based on whether the previous command completed successfully

cd - will switch you to the previous directory


cd without arguments changes to your home directory, same as cd ~

&& lets you chain shell commands together

cd - switches back to the directory you were previously in