数值类型
数值类型
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>数值类型</title>
</head>
<body>
<script type="text/javascript">
var a, b;
a = 5E2;
b = 1.23e-3;
alert(a + "\n" + b);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>数值类型</title>
</head>
<body>
<script type="text/javascript">
b = 3.12e1;
c = 45.0;
d = .34e4;
e = .24e-2;
alert(b + '---' + c + '---' + d + '---' + e);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;"/>
<title>不同进制数值</title>
</head>
<body>
<script type="text/javascript">
var a;
a = 0x13;
var b;
b = 014;
var c;
c = 3.14;
var d;
d = parseInt(c);
alert(a + '---' + b + '---' + c + '---' + d);
</script>
</body>
</html>*
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
var x = 1.79999999737377377477477474e308;
x = x + 1e292;
alert(x);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
var x = -1.79999999737377377477477474e308;
x = x - 1e292;
alert(x);
</script>
</body>
</html>
字符串类型
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
var a = "Abc中国";
var b = a.length;
var c = String.fromCharCode(97, 98, 99);
alert(a+'--'+b+'--'+a.charAt(4)+'--'+a.charCodeAt(4) + '---'+c)
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
var a = "hellojavascript";
var b = a.indexOf("llo");
var c = a.indexOf("llo", 3);
var d = a.lastIndexOf("a");
var f = a.startsWith("hello");
var g = a.endsWith("srip");
var j = a.includes("jaa");
alert(b + "\n" + c + "\n" + d + "\n" + j);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
var s = "abcdefg";
a = s.slice(0, 4);
b = s.slice(1, 4);
c = s.slice(4);
d = s.slice(3, -1);
e = s.slice(2 , -1);
f = s.slice(-3, -1);
alert("s:" + s
+"\na:" + a
+"\nb:" + b
+"\nc:" + c
+"\nd:" + d
+"\ne:" + e
+"\nf:" + f);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
var s = "abfd--abc@d.comcdefg";
a = s.search(/[a-z]+@d.[a-zA-Z]{2}m/);
var str = "1dfd2dfs3df5";
var b = str.match(/\d/g);
alert(a + "\n" + b);
</script>
</body>
</html>
布尔类型
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
if (navigator.cookieEnabled) {
alert("浏览器允许使用Cookie");
} else {
alert("浏览器禁止使用Cookie");
}
</script>
</body>
</html>
undefined和null
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
var x, y = null;
if (x == undefined) {
alert('声明变量默认值为:undefined');
}
if (x == null) {
alert('声明变量默认值为:null');
}
if (x == y) {
alert(" x(undefined) == y(null)");
}
if (String.xyz == undefined) {
alert("不存在的属性值默认为undefined");
}
</script>
</body>
</html>
正则表达式
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body>
<script type="text/javascript">
alert(/^<a href=(\'|\")[a-zA-Z0-9\/:\.]*(\'|\")>.*<\/a>$/
.test("<a href='http://www.crazyit.org'>疯狂Java</a>"));
function trim(s)
{
return s.replace(/(^\s*)|(\s*$)/g, "");
}
alert(trim(' Hello,JavaScript '));
</script>
</body>
</html>
|