javascript基础部分注意事项

来源:互联网 发布:香蕉网络电视 香蕉tv 编辑:程序博客网 时间:2024/05/17 08:50

1.comment://inline comment,/**/multi-line comment.

2.variable:

1)type:data(null(),undefined<uninitialized>,number,boolean,string(length),symbol,object)

2)declare:,字母数字$下划线,数字不可以开头,不含space.大小写敏感,properCamelCase

3)assignment(=)

4)initialize=

5)operation:add,subtract,product,divide,remainder

6)typeof 基本类型判断和"boolean"之类比较

3.\转义",',\,n(ext line),r(eturn),b(backspace),t(able),f(finish page)

4.数组可以存放不同类型数据:

1)push(append element),unshift(insert element before head),pop删除最后一个数据,shift删除第一个元素

2)concat可以连接两个数组

3) delete array[index] 删除元素.

4)indexOf,lastIndexOf查找元素,相当于包含.

5)instanceof Array

5.函数 function functionName(param){}var keyword declare local variable,no var declare global variable,函数内非var 声明变量等同于函数外var声明的变量为全局变量.

1)arguments.length 支持变参函数.

6.全等===判断值和类型,!==非全等(3!=='3'  true),switch case 严格等于

7.if else if 先处理最简单和最少的情况,降低问题复杂度,避免前面条件包含后面条件,//直接返回比较结果.

8.String:

1) char to int:String.fromCharCode(int); int to char:str.charCodeAt();

2)split分割字符串成数组.

3)concat连接数组.

9.Object对象

1)属性访问.or[],属性的名字带有空格,请使用中括号操作符来访问属性的值.

2) 属性操作:添加属性obj.pn=pv即可. delete obj.pn删除属性

3)switch/if 转换为字典对象,hasOwnProperty判断属性是否存在.

4)Json:JavaScript Object Notation 简称JSON 使用JavaScript对象的格式来存储数,SON是灵活的,因为它允许数据结构字符串数字布尔值字符串,和对象 的任意组合.[{pn:pv,pn:pv},{}]

5) instanceof

10.Math:

1)Random随机数:Math.random()用来生成一个在0(包括0)到1(不包括1)之间的随机小数,因此Math.random()可能返回0但绝不会返回1,范围内随机数Math.floor(Math.random() * (max - min + 1)) + min.

2)向下取整:Math.floor(num)

11.Regular expressions正则表达式:/ begin,mode,/end,str.match(expression)返回匹配数组情况,str.replace(expression,str1)替换.

1)find word:/word/gi[global(find all),ignore case]

2)find number:/\d+/g[global,+任意多个]

3)find space(空白字符有 " " (空格符)、\r (回车符)、\n (换行符)、\t (制表符) 和\f (换页符)):/\s+/g;

4)find not space:/\S/

13.jquery:$(".class array,$("# id element. html()get html(value) set

14.最后也最主要:复制粘贴,不要过多敲击键盘.

原创粉丝点击