js注释
1.
2. 多行注释
js变量类型
1. 字符串
2. 整型
3. 浮点
4. 布尔
5. 数组
6. 对象
7. json对象
8. NaN
9. null
10. undefined
第一种 字符串
<script>
// 第一种 字符串
username='小金' ;
document.write ('<h1>' +name+'</h1>' );
document.write ('<h1>' +name+'</h1>' );
document.write ('<h1>' +name+'</h1>' );
document.write ('<h1>' +name+'</h1>' );
document.write ('<h1>' +name+'</h1>' );
document.write ('<h1>' +name+'</h1>' );
document.write ('<h1>' +name+'</h1>' );
</script>
第二种 整型(整数型)
<script >
username=100 ;
alert(username+5 );
alert(username+'5' );
</script >
<script >
username=100 ;
alert(username-'5' );
</script >
第三种 浮点型
<script >
username=100.1 ;
alert(username+5 );
</script >
第四种 布尔
<script >
num=67 ;
if (num>=60 ) {
alert('及格' );
}else {
alert('不及格' );
}
</script >
第五种 数组
<script >
ps=new Array ('xiaojin' ,'xiaoshuai' ,'xiaoming' ,'xiaodong' );
alert(ps);
</script >
<script >
ps=['xiaojin' ,'xiaoming' ,'xiaoshuai' ,'xiaodong' ];
alert(ps);
</script >
第六种 对象
1. js对象
obj=new Object ();
2. dom对象
eleobj=document;
<script >
obj=new Object ();
obj.username='user1' ;
obj.age='20' ;
obj.sex='male' ;
obj.say=function () {
alert('my name is user1' );
}
document.write('my name is ' +obj.username+'<br>' );
document.write('my name is ' +obj.age+'<br>' );
obj.say();
</script >
第七种 json对象
<script >
jsobj={
'username' :'user1' ,
'age' :'20' ,
'sex' :'man' ,
'say' :function () {
alert(1 )
}
};
alert(jsobj.username);
jsobj.say();
</script >
<script >
jsobj={
'username' :'user1' ,
'age' :'20' ,
'sex' :'man' ,
'say' :function () {
alert(this )
alert(this .username)
}
};
jsobj.say();
</script >
this 代表本对象