<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p>JavaScript 数据类型</p>
<p id = "u"></p>
<script>
var u = "李白" + 300 + 900;
document.getElementById("u").innerHTML = u;
</script>
</body>
</html>
JavaScript 数据类型
JavaScript 变量能够保存多种数据类型:
数值、字符串值、数组、对象等等
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p>JavaScript 拥有动态类型</p>
<p id = "动态"></p>
<script>
var h;
var h = 900;
var h = "HTML";
document.getElementById("动态").innerHTML = h;
</script>
</body>
</html>
JavaScript 拥有动态类型
JavaScript 拥有动态类型。这意味着相同变量可用作不同类型
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p> JavaScript 字符串值 </p>
<p id = "d"></p>
<script>
var HTML1 = "前端";
var HTML2 = "后端";
document.getElementById("d").innerHTML = HTML1 + "<br> " + HTML2;
</script>
</body>
</html>
JavaScript 字符串值
字符串(或文本字符串)是一串字符(比如 "HTML CSS")。
字符串被引号包围。您可使用单引号或双引号
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<P>JavaScript 字符串值</P>
<p id = "v"></p>
<script>
var k1 = "HTML";
var k2 = "CSS";
var k3 = "javascript";
document.getElementById("v").innerHTML = k1 + "<br>" + k2 +"<br>"+k3;
</script>
</body>
</html>
JavaScript 字符串值
字符串(或文本字符串)是一串字符(比如 "HTML CSS")。
字符串被引号包围。您可使用单引号或双引号
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p>JavaScript 数值</p>
<p id = "h"></p>
<script>
var o1 = 300;
var o2 = 900;
document.getElementById("h").innerHTML = o1 + "<br>" + o2 ;
</script>
</body>
</html>
JavaScript 数值
JavaScript 只有一种数值类型。
写数值时用不用小数点均可
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p>JavaScript 数值</p>
<p id = "00"></p>
<script>
var u = 900e3;
var p = 100e9;
document.getElementById("00").innerHTML = u + "<br>" + p;
</script>
</body>
</html>
JavaScript 数值
JavaScript 只有一种数值类型。
写数值时用不用小数点均可
超大或超小的数值可以用科学计数法来写