May 28, 2021 Article blog
1. I. If conditional statement
2. Second, switch multi-branch statement
JavaScript has a variety of usages, and you know how to use it for logical statement writing
if(条件)
{ //JavaScript代码; }
else
{ //JavaScript代码; }
If's null, "," "," "undefined," "NaN,false" -- the result is false, except for true.
switch (表达式)
{ case 常量1 :
JavaScript语句1;
break;
case 常量2 :
JavaScript语句2;
break;
default :
JavaScript语句3; }
for(初始化; 条件; 增量)
{ JavaScript代码; }
while(条件)
{ JavaScript代码; }
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.