1.任何地方
添加任意个script标签 然后在标签内部就可以写js代码 :嵌入脚本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//在控制台打印666666
console.log(666666)
</script>
</body>
</html>
2.在标签内部的事件属性中写js代码
行内写js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<a href="javaScript:console.log(680)">去不了百度了</a>
<button onclick="console.log(690)">点我</button>
<a href="javaScript:void(0)">去不了百度了</a>
</body>
</html>
3.js文件中写
外部导入
1.ES5版本
HTML部分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 加载这个js文件 并运行这个js文件(以后学习后端时还继续学) -->
<script type="text/javascript" src="相对路径或绝对路径"></script>
</head>
<body>
</body>
</html>
对应的相对路径或绝对路径的js文件
//同时在外部文件和标签内部写
//只会运行外部文件不会运行脚本标签内部的代码
console.log(700)
2.ES6版本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="module">
import x from "./js/es6.test.js"
console.log(123)
</script>
</body>
</html>
4.在控制台
因为浏览器的控制台其实就是运行js的运行环境