Home > Web Front-end > JS Tutorial > Detailed answers to js basic syntax

Detailed answers to js basic syntax

亚连
Release: 2018-05-17 09:42:56
Original
1402 people have browsed it

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 时执行的代码
  }
Copy after login

2. Switch statement

switch(n)
{
case 1:
  执行代码块 1
  break;
case 2:
  执行代码块 2
  break;
default:
  n 与 case 1 和 case 2 不同时执行的代码
}
Copy after login

3. While statement

格式:while (条件){
  需要执行的代码
 }
Copy after login

4. Do while statement

格式:do
  {
  需要执行的代码
  }
while (条件);
如下:
do
  {
  x=x + "打印的数字是 " + i + "<br>";
  i++;
  }
while (i<8);
Copy after login

5. For statement

格式:for (赋值;逻辑判断;运算){
        //循环体
}
如:for (var i=0;i<100;i++)
{
document.write(100 + "<br>");
}
Copy after login

6. this

<script type="text/javascript">
alert(this==window);
</script>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template