0915ty

1. js是面向对象的动态编程语言,强类型

2. js的强大之处,可编写应用软件,如VS Code, Atom, 可编写web后台服务平台,如nodejs, 还可以编写web后台语言如express,koa等等

3. js的数据类型(总的来说)

  1).String: 字符串

  2).number: 数值型

  3).boolean: 布尔型 (true/false)

  4).Object: 类

    4.1)Function 函数

    4.2)Array 数组

    4.3)Date 日期

    4.4)RegExp 正则表达式

    4.5)Math 数学

  5).null: 空型

  6).undefind: 未定义

4.String字符串类型

  js中带双引号或者单引号的都被称为字符串,python中三引号也是字符串,当然python中有时候程序中可用来做注释,这里不多做解释.

  举个例子 : 'hello world', "hello world"

  介绍一下字符串的基本操作

  var str = 'hello world'

  str.length ===> 返回字符串的长度

  str.charAt(index) ====> 返回字符串的第几个字符, index从0开始

  str.replace('hello', 'good') ====> 将字符串中的hello 替换为 good

  str.splice(start, [end]) ====> 将字符串从start(开始位置)到end(结束位置)截取之间的字符串,并返回. end可不写,即从start开始位置一直截取到最后,并返回.

  str.subString(start, [end]) 方法用于提取字符串中介于两个指定下标之间的字符。=====> start必填,end可选

  str.subStr(start, length) ===>将字符串从开始位置向后截取都少长度, length可选,若不填,则截取到最后边.

  就先说这些常用的.

  在说一下 字符串 <=====> 数组 之间的相互转换

  1.  字符串--->数组

    var str = 'hello world what are you doing'

    console.log(str.split(' ')) //  ["hello", "world", "what", "are", "you", "doing"]

  2. 数组 ----> 字符串

    var arr =  ["hello", "world", "what", "are", "you", "doing"]

    console.log(arr.join(' ')) // hello world what are you doing

  3. ES6 遍历字符串

    for of 循环

    for (i of str) {

      console.log(i) // h e l l o w o r l d w h a t a r e y o u d o i n g

     }

5.number 数值型,与 Math对象之间的使用

  var num = 2

  console.log(num + Math.ceil(Math.random() * 10))
  // Math.ceil()向上取整 , Math.floor() 向下取整 Math.random() 取随机数 Math.random()*10 取0-10之间的随机数
 
6.数组类型

  var arr = [1,2,3,4,5,6,7]

  遍历数组 for循环 ,   for in 遍历数组和对象

  for (i in arr ) {console.log(i) // 1,2,3,4,5,6,7}

  ES6 数组解构赋值

    例:var  [a, b, c] = [1, 2, 3]

      console.log(a) // 1

      console.log(b) // 2

      console.log(c) // 3

      var [a, b] = [1, 2, 3]

      console.log(a) // 1

        console.log(b) // 2

      var [c, d, e] = [1, 2]

      console.log(c) // 1

      console.log(d) // 2

        console.log(e) // undefined

  ES6 扩展运算符 数组中的用法

  ...    -----> 三个点就是ES6的扩展运算符

    使用方法 

    var arr = [1,2,3,4,5,6,7]

    console.log(...arr) // 1,2,3,4,5,6,7

    扩展运算符的很强大.具体接下来的内容详谈.

相关文章: