1.Writing into an HTML element, using innerHTML
.
<!DOCTYPE html> <html> <body> <h2>My First Web Page</h2> <p>My First Paragraph.</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = 5 + 6; </script> </body> </html>
document.write()
.
<!DOCTYPE html> <html> <body> <h2>My First Web Page</h2> <p>My first paragraph.</p> <p>Never call document.write after the document has finished loading. It will overwrite the whole document.</p> <script> document.write(5 + 6); </script> </body> </html>
window.alert()
<!DOCTYPE html> <html> <body> <h2>My First Web Page</h2> <p>My first paragraph.</p> <script> window.alert(5 + 6); </script> </body> </html>
console.log()
.
<!DOCTYPE html> <html> <body> <h2>Activate Debugging</h2> <p>F12 on your keybord will activate debugging.</p> <p>Then select "Console" in the debugger menu.</p> <p>Then click Run again.</p> <script> console.log(5 + 6); </script> </body> </html>