How to remove spaces from a string variable in bash?

In a bash script, spaces can be quickly removed as follows,

echo ${myvar// } # this will remove all spaces in $myvar

Let us look at a detailed example,

Remove spaces from a string

dev@codetryout:~$ myvar="  "
dev@codetryout:~$ echo $myvar

dev@codetryout:~$

Empty line. Let us make it more visible:

dev@codetryout:~$ echo START${myvar}END
START END
dev@codetryout:~$ echo START${myvar//}END
START END
dev@codetryout:~$ 

Now, let us replace all spaces in it

dev@codetryout:~$ echo START${myvar//}END
START END
dev@codetryout:~$ echo START${myvar// }END
STARTEND
dev@codetryout:~$ 

Removing multiple spaces from a string

One more example, altogether, where the spaces between the word and numbers were deleted.

dev@codetryout ~> myvar="codetryout 1 2 3"
dev@codetryout ~>
dev@codetryout ~> echo ${myvar// }
codetryout123