# 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 執(zhí)行g(shù)ulp lint下的命令
- vi t.ts
- gulp ts -> 轉(zhuǎn)為js
## 1
- 建一個項目 就需要一個目錄(所有開發(fā)的代碼)
- 自定義的配置(gulp babel etc)
- 調(diào)試代碼
- 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 數(shù)值 字符串 元組
- chrome -更多工具 開發(fā)者工具
- addition emmet
- alias jsc='/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc'
# Chapter 2
- 強(qiáng)類型 vs 弱類型
-- var a:number = 1;
- var vs let
-- 可以定義兩次變量 僧凤?
- pythontutor
- var 和函數(shù) 在編譯的時候會放在前面汤善,let不放在前面
- 變量第一個不能是數(shù)字爽撒,無法和數(shù)字進(jìn)行區(qū)分
- 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;
- 事實上就是看運(yùn)行到什么地方,返回給最后一個
- var a = b = 1; x
-- 先運(yùn)行b = 1,有了返回值然后a = 返回值;
# Chapter 3
-? function arguments
- 變量默認(rèn)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";
};
};
- 數(shù)組序號存儲在堆里面裹唆,序號代表偏移區(qū)間
var a = 0;
if (a) {
function aname() {
// keyibeidiaoyong
}
}
- arguments[]? //? 類似數(shù)組
- Array.prototype.silce(arguemnts)
- 函數(shù)的定義是放在最前面的
- aname.length() 行餐叔 arguemtns()給了幾個參數(shù)
- var c = Array.prototype.slice.call(arguments);
console.log(c.reduce(function(a, b)))
- 函數(shù)的參數(shù)的作用域是夾在out && in
- rest parameters ...quotes
- spread operator
- apply call bind
- 在let a之前 調(diào)用a是錯誤的
- Constants are block-scoped just like variables created? ? using the let keyword
- Functions are data
- a()() 直接執(zhí)行函數(shù)和她的返回值 p98
- a() 只返回鏈接
- imiediate function返回鏈接的話可以直接執(zhí)行
- three scope
-- global, function, code block(let,const)
-- global 運(yùn)行在瀏覽器誓斥,所有的變量或者方法屬于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
// 函數(shù)參數(shù)是函數(shù)內(nèi)部的變量,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]
```
兩種區(qū)別
---
myTest();
test? //. 都會報錯,這種方式不能在函數(shù)之前調(diào)用
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
```