How to add or update a query string parameter using JavaScript?

How to add or update a query string parameter using JavaScript?