var x = 30; //变量初始化
var y; //var声明变量
y = 50; //变量赋值
var name ='aaa'
变量类型
/// number string boolean undefined null//number var a =3;var b =1.234;var c =-1alert(typeof a |);//检验数据类型//string 用'' 或""var d ='a';var e ='1';//boolean 0(假 false)和1(真 true)var f =3<4;alert(f);//返回false//undefinedvar g;//未定义值 返回undefined//nullvar h =null;//返回null 空对象
运算
//算数运算符var x =10;var y =4;var sum = x + y;//加法var en = x - y;//减法var or = x * y;//乘法var op = x % y;//余数//赋值运算符
x =3;
x++;//加加
x--;//减减//数值和字符串转换var num =234;var mystr = num +'';//隐式转换var num =Number(num);//字符串转数字var str = num.toString();//数字转字符串var a =1;
a.toString();//数值转字符串// alert(typeof b)Number(b)//字符串转数值
逻辑语句
//switch语句 1对多的比较switch(key){case value:break;default:break;}//for循环for(;;)//死循环//跳出当前循环break//跳出当前循环下次循环继续continue//while循环// 先判断再循环var x =0;var y =99;while(y>0){
x+=1;
y = y-1;}//do while 循环//先循环在判断var sum =0;var i =1;do{
sum = sum+i;
i++;}while(i<=1);
函数表达式
//方法1functiona(x,y){
z = x+y
return z;//返回值}//调用name(1,2);//返回z//方法2vardiv=functionb(x,y){// z 为局部变量 外部访问不到var z = x+y;return z;}div(1,2)//关于外部js引入导致的全局污染(两个外部js内的函数名相同)(function(){functiona(x,y){var z = x+y;return z;}//将方法a挂载到windows里面//外部就可以用windows上
window.one = a;})();//外部可以通过a()访问//类似于给这个函数换一个名字a()
变量var x = 30; //变量初始化var y; //var声明变量y = 50; //变量赋值var name = 'aaa'变量类型/// number string boolean undefined null//number var a = 3;var b = 1.234;var c = -1alert(typeof a | ); //检验数据类型//st...