Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript logical control statement


May 28, 2021 Article blog


Table of contents


JavaScript has a variety of usages, and you know how to use it for logical statement writing

I. If conditional statement

if(条件)
 
{  //JavaScript代码;  }
 
else//JavaScript代码;  }

If's null, "," "," "undefined," "NaN,false" -- the result is false, except for true.

Second, switch multi-branch statement

switch (表达式)
 
{  case 常量1 :
 
      JavaScript语句1;
 
  break;
 
   case 常量2 :
 
        JavaScript语句2;
 
  break;
 
default :
 
      JavaScript语句3;  }

Three, for, while loop statements

for(初始化;  条件;  增量)
 
 {  JavaScript代码;  }
 
while(条件)
 
 {  JavaScript代码;  }

Four, for - in

var fruit=[ "apple", "orange", "peach","banana"];
 
for(var i in fruit){
 
   document.write(fruit[i]+"<br/>");  }

i is the subscript for the array, and the in array queries all arrays for the subscript

That's all you need to do with the JavaScript logical control statement.