解构 作用域 if else switch case loop

  

 

解构

复制代码
var parts = ['shoulder', 'knees']
var lyrics = ['a', ...parts, 'b', 'c']  // 使用... 解构

console.log(lyrics)

function f(x, y, z) {
    console.log(x + y + z)
}

var args = [2, 3, 4]
f(...args)
复制代码

 

 

条件判断

复制代码
if(cond1){
    pass
}
else if(cond2){
    pass
}
else if(cond3){
    pass
}
复制代码

 

复制代码
条件false等效
false
undefined
null
0
NaN
''
复制代码

 

switch  case

复制代码
switch(expression){
    case label_1:
        statements_1
        [break;]
    case label_2:
        statements_2
        [break;]
    default:
        statements_default
        [break;]

}
复制代码

 

作用域

复制代码
function f(){
    let a=1;
    var b=2;
    c=3;
}

if(1){
    let d=4;
    var e=5;
    f=6;
    if(true){
        console.log(d,e,f)
        console.log('~~~~~~~~~~~~~~~~~')
        g=10
        var h=11
    }
}

// console.log(a)
// console.log(b)
// console.log(c)
// console.log(d)
console.log(e)
console.log(f)
console.log(g)
console.log(h)
复制代码

 

复制代码
let b='1';
switch(b){
    case 1:
    case 2:
        console.log(2)
        break;
    case 3:
        console.log(3)
    default:
        console.log(null)
        break;
}
复制代码

 

loop

复制代码
arr=[1,2,3,4,5,6]
for(i=0;i<arr.length;i++,i++){
    console.log(i,arr[i])
}
if(1)return
i=0;
while(i<arr.length){
    console.log(i,arr[i])
    i+=2
}
复制代码

 

复制代码
let x=10;
while(x--){
    console.log(x)
}

console.log(x)

do{
    console.log(x)
}while(x++<10)

console.log(x)
复制代码

 

复制代码
// for(i=1;i<10;i+=1){-
//     for(j=1;j<=i;j++){
//         console.log('${i}*${j}=${i}*${j}')
//     }
//     console.log()
// }

arr=new Array(10,20,30,40,50)
console.log(arr instanceof Array)
console.log(arr[1],arr['1'])
function sub(x,y){
    return x-y;
}

var obj={
    p1:111,
    p2:'abc',
    p3:[1,2,3],
    p4:sub
}

for(x in arr){
    console.log(x,arr[x],arr.x)
    console.log(typeof x)
}
console.log(obj instanceof Object)
for(x in obj){
    console.log(x,obj[x],obj.x)
    console.log(typeof x)
}
console.log(obj['p1'],obj.p1)
console.log(obj.p4(7,9.2))

for(let i of arr){
    console.log(i,typeof i)
}
复制代码

 

posted @   ascertain  阅读(125)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示