Directory:

  1. The script tag
  2. Output statements

Script tag

  1. Write directly in HTML:
<! DOCTYPE html> <html> <head> <title></title> </head> <body> <scripttype="text/javascript"</script> </body> </ HTML >Copy the code
2. Create js files and separate HTML files:

<! DOCTYPE html> <html> <head> <title></title> </head> <body> <scripttype="text/javascript" src='script.js'></script>

</body>
</html>Copy the code
Then you can write js code in script.js.

Second, js output statement

Js output statements, such as document.write, console.log, etc.
1. Document. write: Outputs text content on the page.

Code:

<! DOCTYPE html> <html> <head> <title></title> </head> <body> <scripttype="text/javascript">
document.write("Output text content.")
</script>

</body>
</html>Copy the code
Effect:

2. Console. log: Outputs content on the console.

Code:

<! DOCTYPE html> <html> <head> <title></title> </head> <body> <scripttype="text/javascript">
console.log("Output text content");
</script>

</body>
</html>Copy the code
Effect:

Console is displayed in the console. Right-click on a review element (or F12) in the browser and you will see the console content.