print object in console javascript code example

Example 1: how to print to console javascript

console.log("string")

Example 2: print object javascript

str = JSON.stringify(obj);
str = JSON.stringify(obj, null, 4); // (Optional) beautiful indented output.
console.log(str); // Logs output to dev tools console.
alert(str); // Displays output using window.alert()

Example 3: javascript print to console

console.log("To Print");

Example 4: console.log printing object object

require('util').inspect.defaultOptions.depth = null