2020-8-25 JavaScript 基础巩固(变量,循环)

JavaScript

变量

  1. let
  2. var
  3. const
区别

let和var用来定义变量,const用来定义常量

let和const只能在自己的作用域的范围内使用

var可以在全局范围使用

		{
            var name = 'zhangsan'
            console.log(name)
            let age = 20
            console.log(age)
        }
        console.log(name)
        console.log(age)

[(C:\Users\Romantic-YanX\AppData\Roaming\Typora\typora-user-images\image-20200825202841605.png)]

if语句

		var passcode = 'YanX'
        if (passcode === 'YanX') {
            console.log('成功')
        } else {
            console.log('失败')
        }

[(C:\Users\Romantic-YanX\AppData\Roaming\Typora\typora-user-images\image-20200825203147413.png)]

switch … case … 语句

		var passcode = prompt('请输入属性名称')
        switch (passcode) {
            case 'color':
                console.log('颜色')
                break;
            case 'fontsize':
                console.log('字体大小')
                break;
            default:
                console.log('没有这种属性')
                break;
        }

在这里插入图片描述
在这里插入图片描述

switch case 语句的判定是严格相等的(‘10’===10)false

while 语句

		let x = 3;
        while (x > 0) {
            console.log(x)
            x--
        }

[(C:\Users\Romantic-YanX\AppData\Roaming\Typora\typora-user-images\image-20200825204541980.png)]

do while 语句

会在判断之前先执行一次

		let x = 3;
        do {
            x--
            console.log(x)
        } while (x > 0)

[(C:\Users\Romantic-YanX\AppData\Roaming\Typora\typora-user-images\image-20200825204736379.png)]

for 语句

		for (let i = 0; i < 3; i++) {
            console.log(i);
        }

[(C:\Users\Romantic-YanX\AppData\Roaming\Typora\typora-user-images\image-20200825204215813.png)]

break 和 continu

		for (let i = 0; i < 6; i++) {
            while (i === 4) {
                break;
            }
            console.log(i)
        }

在这里插入图片描述

break 是跳出整个for循环

		for (let i = 0; i < 6; i++) {
            if (i === 4) {
                continue;
            }
            console.log(i)
        }

在这里插入图片描述

continu 是跳出当前这一次循环

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值