js 總結一下條件語句優化

2022-07-04 03:15:11 字數 912 閱讀 4033

【筆記】

1

//簡單的語句用三目運算子也可以的(除了需要return的)

2 1 == 1 ? console.log('執行了...1') : console.log();

3 1 == 2 ? console.log('執行了...1111') : 2 == 2 ? console.log('執行了...2') : console.log();45

//條件重構前(條件多了以後,一動就要看懂所有邏輯!)

6if (1 || 1) else

9if (a == 2 || 2)

1213

//switch case

14switch (1)

2223

//條件重構後(條件多少無所謂)

24 const mapstatus =,

28 2: () =>31}

3233

//為false的情況有以下幾種,以下情況皆可通過 || 條件來賦值預設

34 mapstatus[undefined || 1](); //

undefined是定義了但沒賦值

35 mapstatus['' || 1]();

36 mapstatus[false || 1]();

37 mapstatus[0 || 1]();

38 mapstatus[nan || 1](); //

nan 是轉換資料格式錯誤

39 mapstatus[null || 1](); //

null是被定義但未被賦值

稍微總結一下

其實整個程式16日的時候應該已經搞得差不多,文件也已經比較詳細。但是由於這個禮拜又是筆試又是面試,所以都沒有時間review整個程式。今天看了一下,改了一些輸出檔案的位置,基本上完成了所有任務了。程式放在 http xiao 81 svn auto testing 下。其中包括三個可執行指令碼 1....

總結一下模板

二叉樹的各種操作 include include include includetypedef struct node tree void createbitree tree p 建樹 return void xpreorder tree p 輸出先序 void zpreorder tree p 輸...

隨便總結一下

資訊和人是主體也是核心。兩者需要進行測算。資訊是由頭,體,鍵,三部分構成。所謂頭,是題目,簡介,id,等,也就是乙個代表或者叫名,總之就是這樣類似的乙個東西。我不能把這種東西說的真正明白,因為其完全是代表性的,而代表性的不是自身,所以不能明確。體,是資訊的核心內容。這個不需要過多解釋。乙個人,不如說...