In this article we will provide you code to print in javascript language. By printing you could mean two things –
- Printing the webpage in printer
- Displaying the content like
printf
inc
language.
Code Example –
1. To print the webpage in printer or as PDF –
window.print()
2. To print the content on console/terminal window –
a. Printing a table –
console.table(["Tony", "Steve", "Bruce"])
output –
Using an object –
console.table({"first name": ["Tony", "Steve", "Bruce"], "last name": ["Stark", "Rogers", "Banner"]})
Output –
b. Printing debug logs –
console.debug("This is a debug log");
c. Printing error logs –
console.error("This is error log");
d. Printing info logs –
console.info("This is info log");
e. Printing warning logs –
console.warn("This is warn log");
f. Printing normal logs –
console.log("This is normal log");
g. Printing timer logs – Use it to get how much time an operation took –
console.time("answer time"); alert("Click to continue"); console.timeLog("answer time"); alert("Do a bunch of other stuff…"); console.timeEnd("answer time");