Skip to content

Instantly share code, notes, and snippets.

@yardfarmer
Created September 16, 2014 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yardfarmer/e01ea16140d6f7802265 to your computer and use it in GitHub Desktop.
Save yardfarmer/e01ea16140d6f7802265 to your computer and use it in GitHub Desktop.
:#javascript 权威指南笔记
## 第1章 概述
## 第2章 词法结构
所谓直接量(literal) .就是程序中直接使用的数据值
## 第3章 类型、值和变量
Javascript 是一种面向对象的语言。这意味着不再需要定义全局的函数去操作不同类型的值——数据类型本身可以定义方法来使用值。
数字、布尔值、null和undefined属于不可变类型
JavaScript变量是无类型的(untyped) ,变量可以被赋予任何类型的值
JavaScript采用词法作用域(lexical scoping)。不在任何函数内声明的变量称做全局变量(global variable) ,它在JavaScript程序中的任何地方都是可见的.
JavaScript中的所有数字均用浮点数值表示。
Math.poW(2 , 53) => 90199254740992: 2 的53次
Math.round(.6) => 四舍五入
Math.ceil(.6) => 向上求整
Math. f1oor(. 6) => 向下取整
Math.abs(-5) => 求绝对值
Math.max(x,y,z,e,f) => 所有参数中的最大值
Math.min(x,y,z) => 所有参数中的最小值
Math.random() => 生成一个大于等于0 小于1. 0的伪随机数
Math.PI
Math.E
Math.sqrt(3)
Math.pow(3 , 1/3)
JavaScript中的非数字(NaN)值有一点特殊:它和任何值都不相等,包括自身 NaN != NaN
var now = new Date(); //当前日期和时间
var elapsed = now - then; //日期减法 计算时间间隔的毫秒数
字符串(string) 是一组由16位值组成的不可变的有序序列,每个字符通常来自于 Unicode字符集,比如can't,'Reilly's 。因为撇号和单引号是同一个字符,所以必须使用反斜线来转义
var s = "hello, world"
s.charAt(o);
s.charAt(s.length-1)
s.substring(startIndex,endIndex)
s.substr(startIndex,length)
s.slice(1,4)
s.slice(-3)
s.indexOf("l")
s.lastlndexOf("l")
s.indexOf("l", 3)
s.split(", ") 字符串分割成数组,相对于 Array.join()
下面这些值可以被转换成 false
undefined
null
0
-0
NaN
"" // 空字符串
## 第4章 表达式和运算符
var a,b = 0;
(a = b) == 0 // => true
先执行括号内的赋值语句, 后进行相等判断
赋值操作的结合性是从右到左
所以,可以
i = j = k = 0;
`data[i++] = data[i++] *2 `
由于所有 对象和数组 的typeof运算结果是"object" 而不是"function",因此它对于
区分对象和其他原始值来说是很有帮助的, function 的 typeof 才是 "function"。
如果想区分对象的类,则需要使用其他的手段,如使用instanceof运算符
var a = [1,2,3,4];
delete a[3]; => [1, 2, 3, undefined × 1]
a.length => 4;
// 只是在原位置抹去了,但空位置还留着,长度不变
通过 var 声明的变量是不能删除的,所以 没 var 生成的变量是可删除的。
## 第5章 语句
//适用空语句,初始化一个数组a
for(i = 0; i < a.length; a[i++] = 0) ;
## 第6章 对象
## 第7章 数组
## 第8章 函数
## 第9章 类和模块
## 第10章 正则
## 第11章
## 第12章
## 第13章
## 第14章
## 第15章
## 第16章
## 第17章
## 第18章
## 第19章
## 第20章
## 第21章
## 第22章
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment