青春是一個不堪回首卻有靦腆的衝動

chapter3

simple, just do one thing in a function.

If a paragraph of code do three things, have better seperide those three things to individual three functions.

And giving them a meanful name, it can help developer more fast to understand those functions.

1. switch narrative

A&B 發表在 痞客邦 留言(0) 人氣()

char 1 

If we wirte a clear code for our project, it will help a lot to read and maintenance in the future.

Another reason is if others engineers need to join or fix this project, it's more easy to understand the original develop.

As the ressons, spend more time to write a clear code is more efficient than spend time to fix again and again.

char2

A&B 發表在 痞客邦 留言(0) 人氣()


https://jsbin.com/wonihum/8/edit?html,js,output

簡單的來說RegExp就是在指定的字串中搜尋特定的字元。

test()如果該字串中有出現特定字元

回傳值為 ture

test()如果該字串裡沒有特定的字元

A&B 發表在 痞客邦 留言(0) 人氣()


https://jsbin.com/wonihum/4/edit?html,js,output

利用search搜尋指定字元的起始位置("指定字元")

利用replace搜尋特定元素中的字串並做取代 ("A","B")

A&B 發表在 痞客邦 留言(0) 人氣()


https://jsbin.com/wonihum/2/edit?html,js,output

在寫code的時候要了解各個數值的類型,才能有效地知道後續如何去做規劃。

利用typeof 回傳數值的屬性。

John為字串

3.14為數字

A&B 發表在 痞客邦 留言(0) 人氣()


https://jsbin.com/wonihum/1/edit?html,js,output

這次來探討break 跟continue的差別。

以中文字面上翻譯 break 是斷  , continue是繼續

那這樣就很清楚的知道,

一但遇到break就直接跳出當下的迴圈。

A&B 發表在 痞客邦 留言(0) 人氣()


https://jsbin.com/wonihum/edit?html,js,output

先來說說switch的基本架構

switch( parameter ){

     case 0 :    ;    //  when parameter is 0 , run this case.

          break;

A&B 發表在 痞客邦 留言(0) 人氣()


variablename=(condition)?value1:value2

condition內的條件是如果成立,那麼va的值為value1否則為value2

https://jsbin.com/conasenifo/1/edit?html,js,output

可以試著run以上程式

圖中script宣告age可以省略

A&B 發表在 痞客邦 留言(0) 人氣()


今天在學javascript的過程中看到一句百思不得其解的一句話

" 不要创建 String 对象。它会拖慢执行速度,并可能产生其他副作用 "

經過廣大前輩的討論後,來總結一下

我們拿兩個例子來說明:

let a = "abc";

A&B 發表在 痞客邦 留言(0) 人氣()

在javascript中單引號及雙引號,是要告訴電腦這串文字為字串

但如果要傳達的資料內容中包含著單引號,雙引號,或者其他特殊字元時該怎麼辦?\

EX: "She is my girlfriend "Ada""

這樣的話這串文字就會被電腦截斷

所以javascriot就有一組自己的解決方案。

A&B 發表在 痞客邦 留言(0) 人氣()


https://jsbin.com/rinugisevi/1/edit?html,js,output

使用屬性length計算字串長度

A&B 發表在 痞客邦 留言(0) 人氣()


https://jsbin.com/pepupajobu/1/edit?html,js,output

整理一下這幾種方法可以,顯示當地時間

第一種: 最基本常見的方法,利用document.getElementById("")對指定的id元素進行HTML內容修改

第二種:直接指定當下的元素修改HTML內容(我認為其中缺點就是根本不知道點擊前的HTML內容,直接覆蓋掉)

第三種:利用function設定函數,並呼叫該函數。

A&B 發表在 痞客邦 留言(0) 人氣()

Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。