You debug your client-side code using the developer tools of your browser, like you would debug any modern JavaScript web-based application.
To debug your backend code, you can log console messages on the backend and they will appear in the Developer Console when you preview your site.
Read more about testing and debugging your Wix Code site here.
h/t to Andreas for the suggested post.