Several common basic simple judgments in js, detailed answers to loop syntax
1.if statement
if (条件 1) { 当条件 1 为 true 时执行的代码 } else if (条件 2) { 当条件 2 为 true 时执行的代码 } else { 当条件 1 和 条件 2 都不为 true 时执行的代码 }
switch(n) { case 1: 执行代码块 1 break; case 2: 执行代码块 2 break; default: n 与 case 1 和 case 2 不同时执行的代码 }
3. While statement
格式:while (条件){ 需要执行的代码 }
4. Do while statement
格式:do { 需要执行的代码 } while (条件); 如下: do { x=x + "打印的数字是 " + i + "<br>"; i++; } while (i<8);
格式:for (赋值;逻辑判断;运算){ //循环体 } 如:for (var i=0;i<100;i++) { document.write(100 + "<br>"); }
6. this
<script type="text/javascript"> alert(this==window); </script>
The pop-up box displays: true.
It can be seen that this is the current window.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Detailed explanation of the steps to call the cache to implement the JS method
JS summary of judging whether a certain string contains content
How to use the V-bind instruction in VueJs
The above is the detailed content of Detailed answers to js basic syntax. For more information, please follow other related articles on the PHP Chinese website!