一. 变量定义

var a = 10 // 应用var 关键字定义局部变量;函数内定义,函数外不能拜访a = 10  // 不应用关键字 定义全局变量;函数内定义,函数外也能拜访let a = 10 // 定义代码块内变量 ; 块内定义,块外不能拜访

二. 数据类型

var a = ["a", "b", "c"] //数组var pi = 3.14 // 数值var str = "This is a string" // 字符串var person = {"name":"LiMing", "age":15} // 对象,Json格局

三. 循环遍历

  • 按下标循环数组
var a = ["a", "b", "c"]for ( i in a){    console.log(a[i])}
  • 按key 循环Json对象
person = {"name":"John", "age": 10}for( i in person ){    console.log(person[i])}

四. 异样捕获

function testRun(a,b){    c = a + b    console.log(c)}try{    testRunnnn(1,2) // 写错函数名} catch(err){    console.log(err)}

五. 函数异步

async function test(){    console.log(1)}test() // 调用异步函数console.log(123) // 不会期待下面的函数执行实现而间接执行

六. 罕用函数

  1. parseInt() 强制转换为int
var x = "888"var y = parseInt(x) // 转为Intconsole.log(y) //输入888
  1. Math.cell() 小数向上取整
var x = 1.4var y = Math.ceil(x) // 1.4 向上取整console.log(y) //输入 2
  1. Date() 日期函数
var today = new Date() // 获取以后工夫console.log(today) // 输入 ' Fri Oct 08 2021 15:42:27 GMT+0800 (中国规范工夫) ' 
  1. concat() 合并数组
list_1 = [1,3,5]list_2 = [2,4,6]list = list_1.concat(list_2)console.log(list) // [1,3,5,2,4,6]