js - sum up the conditional statement optimization

【notes】

1  // simple statement with ternary operator also possible (in addition to the return) 
2              1 == 1 the console.log ( '1 performed ...'? ): The console.log ();
 . 3              1 == ?? 2 console.log ( 'executed ... 1111'): 2 == 2 console.log ( ' 2 executed ...' ): console.log ();
 4  
5              // condition before reconstruction ( conditions more after a move is necessary to read all of the logic)! 
. 6              IF (||. 1. 1 ) {
 . 7                  the console.log ( 'performed. 1 ... - ... the else IF' );
 . 8              } the else 
. 9              IF (a || 2 == 2 ) {
 10                  the console.log ( '... performed 2' );
 11              }
 12 is  
13 is             //   Switch Case 
14              Switch (. 1 ) {
 15                  Case . 1 :
 16                      the console.log ( '1111 - Case' )
 . 17                      BREAK ;
 18 is                  default :
 . 19                      the console.log ( '2222' );
 20 is                      BREAK ;
 21 is              }
 22 is  
23 is              / / conditions reconstituted (it does not matter how many conditions) 
24              const mapStatus = {
 25                  1: () => {
 26 is                      the console.log ( 'performed ... 1' );
 27                 },
 28                  2: () => {
 29                      the console.log ( '... performed 2' );
 30                  }
 31              }
 32  
33 is              // case where false are the following, where the following conditions are serviced by || default be assigned 
34 is              mapStatus [|| undefined. 1] (); // undefined but no assignment is defined 
35              mapStatus [ '' ||. 1 ] ();
 36              mapStatus [ to false ||. 1 ] ();
 37 [              mapStatus [ . 1 || 0 ] ();
 38 is              mapStatus [|| NaN3. 1] (); // NaN3 is to convert a data format error
39              mapStatus [ null ||. 1] (); // null is defined but not yet assigned

 

Guess you like

Origin www.cnblogs.com/cisum/p/11234494.html