---
# System prepended metadata

title: javascript 學習筆記

---

##### 學習歷程
# javascript 學習筆記


## 變數
---
建立初始化數值或建立賦值

```=javascript
var x =5;//宣告變數
const x =5; //宣告常數
let x=5; //ES6新增變數
```

## 判斷式
---

如果外面天氣是下雨需不需要帶雨傘，沒有就不用帶雨傘，很多例子可以幫助我們判斷程式邏輯思考。

以下情境如果買超過10個蘋果就打折，沒有超過數量就按照原價計算。
```＝javascript

    var　price = 80
    var trade = 0.7
    var conunt = 11
    var total = price * conunt 
    if(conunt > 11){
    total = price * conunt * trade　// 打折的金額是６１６
    }else{
     total = price * conunt // 假設數量是９原價就是７２０
    }
```

## 陣列
---
建立一個陣列為色彩，方便調用

```=javascript
var colors = ["red","green","blue"];
```
### Length

抓出陣列長度

```=javascript
colors.length // 3
```
### Reverse
反轉陣列結果

```=javascript
colors.reverse // ["blue","green","red"]
```

### Push
在末端增加一個陣列，並且回傳陣列的長度。

```=javascript
colors.push(["white"]) // 4
colors //  ["red","green","blue","white"];
```

### pop

移除陣列，並回傳陣列的最後一個元素

```=javascript
colors.pop() // white

```

### Concat

將陣列兩組不同陣列合併

```=javascript
var books1 = ['a','b']
var books2 = ['c','d']
console.log(books1.concat(books2)) // ["a","b","c","d"]
```

### Join

將陣列轉換成字串方式連接

```=javascript
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let text = fruits.join(); // Banana,Orange,Apple,Mango

```

### Split

將字串分割成陣列形式
```=javascript
var str = 'a,b,c,d,e';

var strAry = str.split(',');
// 輸出 ["a", "b", "c", "d", "e"]
console.log(strAry);
```