本来没打算写这个的,结果写css写的很烦躁,啊!!!然后乖乖过来写这个了。。。。
焦躁的SH。。。QAQ。。。。
基础
-
JavaScript包含:
ECMAScript 基础语法
DOM 文档对象模型
BOM 浏览器对象模型 -
浏览器弹出框 alert() 和 prompt() 【两个都属于DOM???还是BOM??不确定。。后续补充】
var a=prompt(); alert(a); // console.log(a); -- 控制台输出
-
控制台输出 console.log() console.warn() console.error()
var a=prompt(); console.log(); 正常 console.warn(); 警告 console.error(); 错误
-
变量名由 数字、字母、下划线、$ 组成
-
赋值
/* 变量 x=undefined y=undefined z=10 */ var x,y,z=10; console.log(x); /* undefined */ console.log(y); /* undefined */ console.log(z); /* 10 */
数据类型
-
6大基本数据类型
number 【typeof:number】 string【typeof:string】 boolean【typeof:boolean】 null【typeof:object】 undefined【typeof:undefined】 object【typeof:object】
6 个 typeof:number、string、boolean、undefined、object、function
undefined 未定义
var a;
alert(a); undefined
alert(typeof a); undefined -
string
== 为值相等
=== 为 值相等+类型相等js中的 ‘’ 和 String() 相同,为基本类型
js中的 new String() 和上述不同,为引用类型var s1='hello 123asd'; var s2="hello 123asd"; var s3=String('hello 123asd'); var s4=new String('hello 123asd'); console.log(s1==s2); /* true */ console.log(s1===s2); /* true */ console.log(s1==s3); /* true */ console.log(s1===s3); /* true */ console.log(s1==s4); /* true */ console.log(s1===s4); /* false */ console.log(s1); /* hello 123asd */ console.log(s2); /* hello 123asd */ console.log(s3); /* hello 123asd */ console.log(s4); /* [String: 'hello 123asd'] */ console.log(typeof s1); /*string*/ console.log(typeof s2); /*string*/ console.log(typeof s3); /*string*/ console.log(typeof s4); /*object*/
java:
a = “123 qwe”;
b = “123 qwe”;
c = new String(“123 qwe”);
a 和 b的值相等,地址相同
a 和 c的值相同,地址不同
运算符
(其他不细说了,与python去比的。。)
-
++ 和 – 为自增、自减 (python没有)
-
== 和 ===
== 值相等
=== 值相等 + 类型相同var a=1; var s='1'; console.log(a==s); /* true */ console.log(a===s); /* false */
-
注意 + 功能
字符串连字符
数字加法
正号(+string ==> 正整数) -
js中没有整除,即 a/b 为浮点数
ps:小例子数字反转
直接用数字时,需要 parseInt(num/10);
var n1=123456; var n1r=0; var i=5; while(n1>0){ var tt=1; for (var j=1;j<=i;j++){ tt*=10; } n1r+=n1%10*tt; n1=parseInt(n1/10); i-=1; } console.log(n1r);
利用字符串
var n2=123456; var s2=n2+''; var s2r=''; for(var i=s2.length-1;i>=0;i--){ s2r+=s2[i]; } console.log(+s2r);