三种书写位置
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./外部式.js"> </script>
</head>
<body>
<button onclick="alert('行内式')"></button>
<script>
alert('内部式')
</script>
</body>
</html>
输入输出
<body>
<script>
//输出
alert('弹出提示框')
console.log('控制台输出')
document.write('页面输出')
//输入
prompt('弹出输入框')
confirm('弹出确认框')
</script>
</body>
结束符
; 分号可写可不写,要么都写,要么都不写,一般都不写。
数据类型
string:''、""、``
number:用于计算的数字,比如身份证号就用string
boolean:true、false
undefined:未定义,只有一个值undefined
null:空值,只有一个值null
连接符
<body>
<script>
let name = 'Adele'
let age = 21
document.write(`姓名:${name} 年龄:${age}`)
</script>
</body>
一定要用反引号``
关系运算符
<body>
<script>
let num = 1
console.log(num)
console.log('1' == 1)
console.log('1' === 1)
</script>
</body>
=赋值运算符
==相等运算符,只比较值,不比较数据类型
===全等运算符,先比较数据类型,再比较值