本文主要是介绍javascript练习,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- <script type="text/javascript">
alert("hello javaScript");
</script>
<script type="text/javascript" src="1.js"></script>-->
<!-- <script type="text/javascript">
var i;
alert(i);//undefined
i=12;
alert(typeof(i));//number;
i="abc";
alert(typeof(i));//string
var a=12;
var b="abc";
alert(a*b);//Nan
var a="12";
var b=12;
alert(a==b);
alert(a===b);
</script>-->
<!-- <script type="text/javascript">
var a=0;
if(a){
alert("0为真");
}else{
alert("0为假");
}
var b=null;
if(b){
alert("null为真");
}else{
alert("null为假");
}
var c=undefined;
if(c){
alert("undefined为真");
}else{
alert("undefined为假");
}
var d="";
if(d){
alert("空串为真");
}else{
alert("空串为假");
}
</script>-->
<!-- <script type="text/javascript">
var a="abc";
var b=true;
var c=false;
var d=null;
alert(a&&b);//true
alert(a&&c);//false
alert(c&&a);//false
alert(a&&d);//null
alert(a||d);//abc
alert(d||a);//abc
alert(d||c);//false
alert(c||d);//null
</script>-->
<!-- <script type="text/javascript">
var arr=[true,1];
for(var i=0;i<arr.length;i++){//true ,1
alert(arr[i]);//12 1 abc
}
alert(arr.length);//2
arr[0]=12;
alert(arr[0]);//12
alert((arr.length));//2
arr[2]="abc";
alert(arr.length);//3
alert(arr[1]);//1
for(var i=0;i<arr.length;i++){
alert(arr[i]);//12 1 abc
}
</script>-->
<!-- <script type="text/javascript">
function fun() {
alert("无参函数fun()被调用了");
}
fun();
function fun2(a,b) {
alert("有参函数fun2()被调用了 a=>"+a+",b=>"+b);
}
fun2(12,"abc");
function sum(num1,num2) {
var result=num1+num2;
return result;
}
alert(sum(100,50));
</script>-->
<!-- <script type="text/javascript">
function fun(a) {
alert(arguments.length);
alert(arguments[0]);
alert(arguments[1]);
alert(arguments[2]);
alert("a="+a);
for (var i=0;i<arguments.length;i++){
alert(arguments[i]);
}
}
function sum(num1,num2) {
var result=0;
for (var i=0;i<arguments.length;i++){
if(typeof(arguments[i])=="number"){
result+=arguments[i];
}
}
return result;
}
alert(sum(1,2,3,4,"abc",5,6,7,8,9));
</script>-->
<!--<script type="text/javascript">
var obj=new Object();
obj.name="华仔";
obj.age=18;
obj.fun=function(){
alert("姓名:"+this.name+" ,年龄:"+this.age);
}
obj.fun();
</script>-->
<script type="text/javascript">
var obj={
name:"国哥",
age:18,
fun:function () {
alert("姓名:"+this.name+",年龄:"+this.age);
}
};
alert(obj.name);
obj.fun();
</script>
</head>
<body>
</body>
</html>
这篇关于javascript练习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!