Blogger Information
Blog 6
fans 0
comment 0
visits 5165
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JavaScript第一课_20190505
下一站
Original
893 people have browsed it

1. 如何正确的声明与定义变量?

实例

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>变量的声明与定义</title>
</head>
<body>
    <script>
   var i;//使用var关键值声明变量,变量的默认值为undefined
   i=0;
   var j=i+2;
   console.log(j);//在控制台输出变量j的值
    </script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


2. 变量的提升是原理,如果实现的?

实例

<!DOCTYPE html>
<html lang="zh-cn">
   <head>
       <meta charset="UTF-8">
       <title>变量的声明与定义</title>
   </head>
<body>
   <script>
       console.log(a);//在打印输出语句前未声明变量,此时输出的值为undefined
       var a=10;//声明变量,并赋值
       //上面的代码会将变量a自动提升到代码的顶部,效果如下:
       //var a;
       //console.log(a);
       //a=10;
   </script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例



3. 分支结构有几种, 多分支与switch的实现过程

分支结构分为单分支、双分支和多分支;

多分支与switch的实现过程:

多分支:

var a=60;

var res='';

if {条件1} {

      返回结果1;

     } else if (条件2) {

       返回结果2;

     } else {

       返回结果3;

     }

//用switch简化上面的代码

var a=60;

var res='';

switch (true) {

        case (条件1):

        res=返回结果1;

        break;

        case (条件2):

        res=返回结果2;

        break;

        default:res=返回结果3;

}




Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post