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

Detailed answers to js basic syntax

亚连
亚连Original
2018-05-17 09:42:561254browse

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

2. Switch statement

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 + "
"; i++; } while (i<8);

5. For statement

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

6. this

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!

Statement:
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