javaScript Functjion

Hello There,
When should I use console.log () and document.write() in javaScript Function?

Use console.log if you want to log a message to the console.

Use document.write if you want to replace everything in an HTML document with whatever you pass to the document.write function. It’s only got specific uses, has lots of caveats and exceptions regarding using it, and doesn’t work in lots of contexts. It’s not hugely useful (mainly just for testing) and you’re very unlikely to need it 99.9999999% of the time.

1 Like

Generally, you’ll use the console for developer methods (errors, debugging, testing) and you’ll use the DOM methods (document.write, element.innerHTML etc) when you want to display something more general: messages to users, for example.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.