控制语句

  if-else 语句

<script>
//控制语句
//if-else格式:
var x = 1
if(x==1){
console.log("this is if")
}else if(x>1){
console.log("this is else if")
}else {
console.log("this else")
}
</script>

  switch语句

<script>
//switch语句
var x = 8;
switch (x){
case 1:alert("this 1");break;
case 2:alert("this 2");break;
case 3:alert("this 3");break;
case 4:alert("this 4");break;
case 5:alert("this 5");break;
case 6:alert("this 6");break;
case 7:alert("this 7");break;
default:alert("nothing")
}
</script>

  for循环语句

<script>
// for循环:for while
// 基本格式:
for(初始化;条件;增量){语句}
for(i=1;i<100;i++){
document.write(i)
document.write('<br>')
} var x = [1,2,3,4,5,6]
for(i=0;i<x.length;i++){
document.write(x[i])
document.write('<br>')
} //不建议使用
var x = ['a','b','c','d']
for(i in x){
document.write('this i,输出:'+i);
document.write('<br>');
document.write('this x[i],输出:'+x[i]);
document.write('<br>');
document.write('----------------------');
document.write('<br>');
}
// this i,输出:0
// this x[i],输出:a
// ----------------------
// this i,输出:1
// this x[i],输出:b
// ----------------------
// this i,输出:2
// this x[i],输出:c
// ----------------------
// this i,输出:3
// this x[i],输出:d
// ----------------------

  
  <body>
   <p>A</p>
  <p>B</p>
  <p>C</p>
  <p>D</p>
  <p>E</p>
  <p>F</p>
  <p>G</p>
  </body>
  //不建议使用的原因
var x2 = document.getElementsByTagName('p')
for(i in x2) {
document.write('this i,输出:' + i);
document.write('<br>');
document.write('this x[i],输出:' + x2[i]);
document.write('<br>');
document.write('----------------------');
document.write('<br>');
}
// this i,输出:0
// this x[i],输出:[object HTMLParagraphElement]
// ----------------------
// this i,输出:1
// this x[i],输出:[object HTMLParagraphElement]
// ----------------------
// this i,输出:2
// this x[i],输出:[object HTMLParagraphElement]
// ----------------------
// this i,输出:3
// this x[i],输出:[object HTMLParagraphElement]
// ----------------------
// this i,输出:4
// this x[i],输出:[object HTMLParagraphElement]
// ----------------------
// this i,输出:5
// this x[i],输出:[object HTMLParagraphElement]
// ----------------------
// this i,输出:6
// this x[i],输出:[object HTMLParagraphElement]
// ----------------------
// this i,输出:length
// this x[i],输出:7
// ----------------------
// this i,输出:item
// this x[i],输出:function item() { [native code] }
// ----------------------
// this i,输出:namedItem
// this x[i],输出:function namedItem() { [native code] }
</script>

  while循环语句

<script>
//while 循环
var i=0;j=0;
while(i<201){
j +=i
i++;
}
document.write(j)
</script>

异常处理

<script>
//异常
//try{主程序}catch(异常){执行}finally{无论是否异常都执行}
//主动抛出异常 throw Error("xxxx")
try{
throw Error("报错了!!!")
document.write("OK")
}
catch (e) {
document.write("异常")
}
finally {
document.write("OK and OK")
}
</script>

JavaScript学习 - 基础(四) - 控制语句/异常处理的更多相关文章

  1. JavaScript学习基础部分

    JavaScript学习基础 一.简介 1.JavaScript 是因特网上最流行的脚本语言,并且可在所有主要的浏览器中运行,比方说 Internet Explorer. Mozilla.Firefo ...

  2. JavaScript学习记录四

    title: JavaScript学习记录四 toc: true date: 2018-09-16 20:31:22 --<JavaScript高级程序设计(第2版)>学习笔记 要多查阅M ...

  3. javascript学习笔记(四) Number 数字类型

    数字格式化方法toFixed().toExponential().toPrecision(),三个方法都四舍五入 toFixed() 方法指定小数位个数  toExponential() 方法 用科学 ...

  4. Javascript学习笔记四——操作表单

    Javascript学习笔记 大多网页比如腾讯,百度云之类的需要登陆,用户输入账号密码就可以登陆,那么浏览器是如何获取用户的输入的呢?今天就记录一下操作表单. 操作表单与操作DOM是差不多的,表单本身 ...

  5. java基础学习总结四(控制语句<顺序、选择、循环>、方法)

    一:结构控制语句 结构控制语句分为3种,顺序语句.选择语句.循环语句. 1:顺序语句 就是自上而下的执行程序,默认执行顺序. 2:选择语句 if结构语句:如果满足条件,则执行该语句. if...els ...

  6. JavaScript学习总结(四)——jQuery插件开发与发布

    jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...

  7. JavaScript学习 - 基础(二) - 基础类型/类型转换

    基础类型 - 数字类型(Number) 1.最基本的数据类型 2.不区分整型数值和浮点型数值 3.所有数字采用64位浮点格式存储,相当于Java和C语言中double格式 4.能表示的最大值 +- 1 ...

  8. JavaScript学习笔记(四)——jQuery插件开发与发布

    jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...

  9. JavaScript学习基础篇【第1篇】: JavaScript 入门

    JavaScript 快速入门 JavaScript代码可以直接嵌在网页的任何地方,不过通常我们都把JavaScript代码放到<head>中,由<script>...< ...

随机推荐

  1. [资源]--IOS捷径大全,众多实用小功能

    一.实用工具 1.支付助手3.0(新) (扫一扫.微信扫码.微信收款.支付宝扫码.Apple Pay.AA付款.查快递.蚂蚁森林.蚂蚁庄园.彩票.股票.运动.淘票票.乘车码.生活缴费.火车票等等): ...

  2. ansible系列8-SSH连接和执行性能优化

    1. 当你的SSH的版本高于5.6时 我们可以直接修改 /etc/ansible/ansible.cfg里面的参数 ssh_args = -C -o ControlMaster=auto -o Con ...

  3. share.js轻松分享/邀请

    GitHub地址 https://github.com/overtrue/share.js 安装 安装的方法很多,大家选择自己合适的进行安装就好. clone $ git clone https:// ...

  4. [CTSC2018] 假面 | 期望 DP

    题目链接 LOJ 2552 Luogu P4564 考场上这道题我先是写了个70分暴力,然后发现似乎可以NTT,然鹅问题是--我没学过NTT,遂脑补之,脑补出来了,下午出成绩一看,卡成暴力分(70)- ...

  5. Office2016自定义安装

    Office2016已经不提供自定义安装功能,而采用C2R安装方式.使用镜像安装时,默认全部安装.想要自定义安装就需要用到微软提供的Office2016部署工具. 步骤 下载并运行微软提供的Offic ...

  6. (reverse)Palindromes hdu2163

    Palindromes 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2163 (此题是为了对于JAVA温故知新的) Problem Description ...

  7. grafana worldPing插件

    worldPing插件安装 官网介绍:https://grafana.com/plugins/raintank-worldping-app/installation 插件下砸地址:https://gr ...

  8. Java_myBatis_逆向工程

    所谓逆向工程,就是根据数据库自动生成项目工程(包括了Interface.POJO.映射文件xml) 逆向工程包:https://github.com/wcyong/mybatisGeneratorCu ...

  9. excel自动化翻译2

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...

  10. 4、JDBC-API

    访问数据库 /** * 在 java.sql 包中有 3 个接口分别定义了对数据库的调用的不同方式: * * Statement * * PrepatedStatement * * CallableS ...