# javascript 笔记
## 1
- confign (sudo)
- node
- npm init ->
- npm install gulp-cli -g
- npm install gulp gulp-eslint eslint --save-dev
- cp uses/gulfile.js .
- gulp lint 执行gulp lint下的命令
- vi t.ts
- gulp ts -> 转为js
## 1
- 建一个项目 就需要一个目录(所有开发的代码)
- 自定义的配置(gulp babel etc)
- 调试代码
- type
- primitive
- number string bool null undefined -> stack
- reference
- array function object -> heap
- stack vs heap -> javas.object 1.2
- thread the smallest sequence of programmed...
- var vs let 阮一峰
- python a = 1 b = 1 vs js .. object
- python
---
>>> a = 1
>>> b = a
>>> id(a)
140520881953992
>>> id(b)
140520881953992
>>> b = 2
>>> id(b)
140520881953968
>>> id(a)
140520881953992
- 可变 VS 不可变
- js 原始不可变
- python 数值 字符串 元组
- chrome -更多工具 开发者工具
- addition emmet
- alias jsc='/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc'
# Chapter 2
- 强类型 vs 弱类型
-- var a:number = 1;
- var vs let
-- 可以定义两次变量 ?
- pythontutor
- var 和函数 在编译的时候会放在前面,let不放在前面
- 变量第一个不能是数字,无法和数字进行区分
- Array.isArray
- 0 ->8 0x->16 0b->2
- parseInt('number', jinzhi) ----> 10
- a = number; a.tostring(jinzhi);
- NaN != NaN;
- Number.isNaN vs isNaN()
- 10 * 'f' --> NaN
- console.log(isNaN('test')) -> true
- console..(Number.isNaN('test')) -> false
- parseInt("100 djfkj") -> 100
- + "100 ddd" -> NaN
- boolean({}) - > true
- var b = b && 1; //b underfined
- var b = 10; ..... b = 1;
- 事实上就是看运行到什么地方,返回给最后一个
- var a = b = 1; x
-- 先运行b = 1,有了返回值然后a = 返回值;
# Chapter 3
- function arguments
- 变量默认var 全局变量
```
var a = 123;
function f() {
var a; // same as: var a = undefined;
alert(a); // undefined
a = 1;
alert(a); // 1
}
```
function a() {
alert('A!');
a = function () {
alert('B!');
};
}
第一次是A!,以后每次都是B!
- var a = "global variable";
var F = function () {
var b = "local variable";
var N = function () {
var c = "inner local";
};
};
- 数组序号存储在堆里面,序号代表偏移区间
var a = 0;
if (a) {
function aname() {
// keyibeidiaoyong
}
}
- arguments[] // 类似数组
- Array.prototype.silce(arguemnts)
- 函数的定义是放在最前面的
- aname.length() 行餐叔 arguemtns()给了几个参数
- var c = Array.prototype.slice.call(arguments);
console.log(c.reduce(function(a, b)))
- 函数的参数的作用域是夹在out && in
- rest parameters ...quotes
- spread operator
- apply call bind
- 在let a之前 调用a是错误的
- Constants are block-scoped just like variables created using the let keyword
- Functions are data
- a()() 直接执行函数和她的返回值 p98
- a() 只返回链接
- imiediate function返回链接的话可以直接执行
- three scope
-- global, function, code block(let,const)
-- global 运行在浏览器,所有的变量或者方法属于windows这个对象
-- var a = 1; console.log(a); console.log(windows.a)
-- setTimeout & setInterval
-- closure
```
var a = 1;
function aname() {
var a = 2; // a = 2
console.log(a);
}
aname(); // 2 , 1
```
```
var a = 1;
function aname(a) {
var a = 2; //. a = 2
console.log(a);
}
aname();
console.log(a) // 2, 1
// 函数参数是函数内部的变量,between outer and inner。。
```
```
var a = [1, 2, 3];
function aname(a) {
a[1] = 5;
console.log(a[1]);
}
aname(a);
console.log(a[1]); // 5, 5
```
```
f = function (i) {return i;}
function (i) {return i;}
for (var i = 0; i < 3; i++) {
b[i] = f(i)
}
2
b
(3) [0, 1, 2]
```
两种区别
---
myTest();
test //. 都会报错,这种方式不能在函数之前调用
var myTest = function test() {
console.log("Hello World");
}
---
- var a = 1; // 没有返回值 add b = a 返回值是1
- a = true && b=5; //. a = 5
- javascript reduce
- parseInt(1e-2)//。0
# chapter 4
```
var original = {howmany: 100};
var nullify = function (o) { o.howmany = 0; };
nullify(original);
original.howmany;
> 0
```
网友评论