About JavaScript Output
JavaScript does not have built-in functions for display, but we are able to display data in different ways:
- into an alert box, using alert() method which displays an alert box with a specified message;
var a = 5; var b = 6; if (a < b){ window.alert("a is less then b"); }
- into the browser console, using console.log(). You may pass as many arguments as you’d like;
var a = 5; var b = 6; if (a < b){ console.debug("a is less then b"); //or console.log (a,b); }
- into an HTML element, using innerHTML property which sets or returns the HTML content of an element;
var a = 5; var b = 6; if (a < b){ document.getElementById("whereToAdd").innerHTML("a is less then b"); }
- into the HTML output using document.write() method.
If is used after an HTML document is fully loaded, it will delete all existing HTML;var a = 5; var b = 6; if (a < b){ document.write("a is less then b"); }
Hello there!
I hope you find this post useful!I'm Mihai, a programmer and online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.
If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!