The first and most reliable way is to use an alert box to send a message.
A browser when it loads this code will popup a message box that say’s hello. It is very simple and very easy to show output to the end user but the alert box should be only used when you need to tell the user one message. The problem with an alert box is it becomes a blocking command and will stop the user from accessing your website until it is closed. Many times I have put this into an infinite loop which will crash the browser or annoy your end user so much then don’t want to receive alerts from your program. So use this one very sparingly so that you don’t send a ton of alerts to the user.
console.log('Hello world!'); console.info('Hello world!'); console.error('Hello world!');
In the above code example it shows three different methods you can call to send debug information to the browsers console message. To see these messages you need to open your developer tools for your current browser to see these messages. This is different for each browser and many times it can even be dependent on the version of your browser. For the current version of Chrome Version 54 it is hidden under the three dots -> More tools -> Developer tools or [CTRL]+[SHIFT]+[I]. Microsoft Edge pressing [F12] or pressing the three dots -> Developer tools. If you have a different browser just check the internet for how to open their developer tools.
The next way is a little more difficult and requires some extra work but we can use this to add HTML code to the page and display it.
document.body.innerHtml += "<div>Hello World</div>"; var div = document.createElement('div'); div.innerHTML = "Hello World too!"; document.body.appendChild(div);
These are typically the most common ways to send output to your users. For debugging I like the console method the best because in many browser if I send an object to the console it becomes something that I can dig into and find what information is being store in the object and not just the object type. A lot of the functionality of the console is dependent on the browser developer so find a browser that has good developer tools and use that to start. But once you have some working code test it in as many different browsers as you can find.