JS学习笔记——分支与循环

if判断

var age=3;
if(age>3){
        alert("haha");
}else if(age<5){
        alert("kuwa");
}else{
        alert("kuwa");
}

while循环,避免程序死循环

while(age<100){
    age=age+1;
    console.log(age)
}

for循环

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

forEach循环

var age=[12,3,12,3,12,3,12,31,23,123];

//函数
age.forEach(funcition(value){
        console.log(value)
}

for...in

复制代码
//for(var index in object){}

for (var num in age){
    if(age.hasOwnProperty(num){
        console.log("存在")
        console.log(age[num])
    
        }
}
复制代码

 

posted @   fight挺  阅读(33)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示