js变量类型:
1.字符串变量
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1-变量类型</title>
</head>
<body>
<script>
//第一种字符串
username ='小金';
document.write('<h1>'+username+'</h1>')
</script>
</body>
</html>
2.整型
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1-变量类型</title>
</head>
<body>
<script>
//第二种整型
//
username ='100';
alert(username-5);
</script>
</body>
</html>
3.浮点
3.141592627
4.布尔
fale true
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1-变量类型</title>
</head>
<body>
<script>
//第二种布尔值
//
num = 67;
if(num>=60){
alert("及格");
}else{
alert('不及格');
}
</body>
</html>
5.数组
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1-变量类型</title>
</head>
<body>
<script>
//数组
ps =['小金','小帅','小明','小东'];
alert(ps);
</script>
</body>
</html>
6.对象
JavaScript对象:
1.js对象
obj =new object();
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1-变量类型</title>
</head>
<body>
<script>
obj = new Object();
obj.age = '20';
obj.name = 'xiaoming';
document.write('<h1>my age is '+ obj.age+'</h1>);
obj.say = function(){
alert(123);
}
</script>
</body>
</html>
2.dom对象
eleobjc = document;
7.json对象
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1-变量类型</title>
</head>
<body>
<script>
jsobj = {'1':'22',
'2':'22'
'say':function(){
alert(123);
}
}
jsobj.say();
</script>
</body>
</html>
8.NaN 类型
# not a number
9.null 类型
# 一般用于提前规划一些变量或给变量赋初值
str= null;
10.undefined 类型
#变量未定义
网友评论