Is it ok to use print() to output a text in JS ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Is it ok to use print() to output a text in JS ?

Want to know is it ok to use print() and console.log() both to output a data.

17th Apr 2023, 1:02 PM
Seniru Himanjana Devapriya
Seniru Himanjana Devapriya - avatar
3 Answers
+ 9
JavaScript does not have any print object or print methods. You cannot access output devices from JavaScript. The only exception is that you can call the window.print() method in the browser to print the content of the current window. <!DOCTYPE html> <html> <body> <h2>The window.print() Method</h2> <p>Click the button to print the current page.</p> <button onclick="window.print()">Print this page</button> </body> </html>
17th Apr 2023, 4:41 PM
JaScript
JaScript - avatar
+ 8
Seniru Himanjana Devapriya Javascript doesn't have a print function for output, there are some ways to display or output data. 1. document.write() 2. console.log() 3. windows.alert() 4. Innerhtml() , which is a method for html elements for add, remove and changing its contents
17th Apr 2023, 1:11 PM
Yasin Rahnaward
Yasin Rahnaward - avatar
+ 1
The most used function is console.log(), but you can use others (yasin rahnaward writed them)
17th Apr 2023, 1:55 PM
Ugulberto Sánchez
Ugulberto Sánchez - avatar