console with js code example
Example 1: display console log in HTML
(function () {
var old = console.log;
var logger = document.getElementById('log');
console.log = function (message) {
if (typeof message == 'object') {
logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />';
} else {
logger.innerHTML += message + '<br />';
}
}
})();
Example 2: what is console in javascript
var str = "Howdy GeeksforGeeks"
var geek = {
book: "harrypotter",
price: "2000"
};
var geek2 = [10, 20, 30];
console.log(str);
console.dir(str);
console.dir(geek);
console.log("geek (log) = ", geek);
console.dir(geek2);
console.log("geek2 (log) = ", geek2);
console.dir("geek2 (dir) = ", geek2);
Example 3: html console text
<script>
console.log('%c text', 'background:---; color:---; font-size:---;');
</script>
Example 4: javascript console
console.log('log-message');
console.warn('warn-message');
console.error('error-message');
console.table('table-message');
Example 5: how to use the javascript console